window.location.href = "/Controller/Action?id=" + historyId + "&check=" + itemfilter;
Wednesday, 1 June 2016
How to split the string in asp.net?
if (!string.IsNullOrWhiteSpace(tempitemnoList))
{
string[] tempNumber = tempitemnoList.Split(new string[] { "/" }, StringSplitOptions.None);
if (tempNumber.Count() > 0)
{
for (int i = 0; i < tempNumber.Count(); i++)
{
if (tempNumber[i] != "")
{
string[] temp = tempNumber[i].Split(new string[] { "," }, StringSplitOptions.None);
if (temp.Count() > 0)
{
if (temp[0] != "")
{
string VendorItemNo = temp[0];
VendorItem item = new VendorItem();
var data = objdb.GetInvoiceImportPriceById(Convert.ToInt32(temp[0])).FirstOrDefault();
if (data != null)
{
}
}
}
}
}
}
}
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
{
string[] tempNumber = tempitemnoList.Split(new string[] { "/" }, StringSplitOptions.None);
if (tempNumber.Count() > 0)
{
for (int i = 0; i < tempNumber.Count(); i++)
{
if (tempNumber[i] != "")
{
string[] temp = tempNumber[i].Split(new string[] { "," }, StringSplitOptions.None);
if (temp.Count() > 0)
{
if (temp[0] != "")
{
string VendorItemNo = temp[0];
VendorItem item = new VendorItem();
var data = objdb.GetInvoiceImportPriceById(Convert.ToInt32(temp[0])).FirstOrDefault();
if (data != null)
{
}
}
}
}
}
}
}
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
Monday, 23 May 2016
How to more than one list value to add another list value in MVC?
*************Employee Model*******************
public classEmployeeModel
{
public EmployeeModel()
{
EmployeeList = new List<EmployeeModel>();
StudentList = new List<EmployeeModel>();
ServiceList = new List<SelectListItem>();
ParentList = new List<SelectListItem>();
GenderList= new List<SelectListItem>
{
new SelectListItem() {Text = "--Select--", Value ="0" },
new SelectListItem() {Text = "Male", Value ="1" },
new SelectListItem() {Text = "Female", Value ="2"},
};
}
public int ID { get; set; }
public string Name{ get; set; }
public string Address{ get; set; }
public int Age{ get; set; }
public string Mobile{ get; set; }
public List<EmployeeModel> EmployeeList { get; set; }
public List<EmployeeModel> StudentList { get; set; }
public IEnumerable<Employee> SerList { get; set; }
public decimal? ServiceUsage { get; set; }
public decimal? ServiceCost_Per_Annum { get; set; }
public decimal? ServiceCost_for_Service { get; set; }
public List<SelectListItem> GenderList{ get; set; }
}
************************End Employee Model**************************
var empList = _apiService.GetAllEmployee().ToList();
model.EmployeeList = stcList.Select(x =>
{
return new EmployeeModel()
{
ID = x.ID == null ? 0 : x.ID.Value,
Name = string.IsNullOrEmpty(x.Name) ? "" : x.Name,
Address= string.IsNullOrEmpty(x.Address) ? "" : x.Address,
Mobile= string.IsNullOrEmpty(x.Mobile) ? "" : x.Mobile,
Age= x.Age == null ? Convert.ToInt32(0) : x.Age,
};
}).ToList();
var stuList = _apiService.GetAllStudent().ToList();
model.StudentList = stuList .Select(x =>
{
return new ComponentModel()
{
ID = x.ID == null ? 0 : x.ID.Value,
Name = string.IsNullOrEmpty(x.Name) ? "" : x.Name,
Address= string.IsNullOrEmpty(x.Address) ? "" : x.Address,
Mobile= string.IsNullOrEmpty(x.Mobile) ? "" : x.Mobile,
Age= x.Age == null ? Convert.ToInt32(0) : x.Age,
};
}).ToList();
var AddExData = new List<EmployeeModel>();
AddExData.AddRange(model.EmployeeList);
AddExData.AddRange(model.StudentList);
public classEmployeeModel
{
public EmployeeModel()
{
EmployeeList = new List<EmployeeModel>();
StudentList = new List<EmployeeModel>();
ServiceList = new List<SelectListItem>();
ParentList = new List<SelectListItem>();
GenderList= new List<SelectListItem>
{
new SelectListItem() {Text = "--Select--", Value ="0" },
new SelectListItem() {Text = "Male", Value ="1" },
new SelectListItem() {Text = "Female", Value ="2"},
};
}
public int ID { get; set; }
public string Name{ get; set; }
public string Address{ get; set; }
public int Age{ get; set; }
public string Mobile{ get; set; }
public List<EmployeeModel> EmployeeList { get; set; }
public List<EmployeeModel> StudentList { get; set; }
public IEnumerable<Employee> SerList { get; set; }
public decimal? ServiceUsage { get; set; }
public decimal? ServiceCost_Per_Annum { get; set; }
public decimal? ServiceCost_for_Service { get; set; }
public List<SelectListItem> GenderList{ get; set; }
}
************************End Employee Model**************************
var empList = _apiService.GetAllEmployee().ToList();
model.EmployeeList = stcList.Select(x =>
{
return new EmployeeModel()
{
ID = x.ID == null ? 0 : x.ID.Value,
Name = string.IsNullOrEmpty(x.Name) ? "" : x.Name,
Address= string.IsNullOrEmpty(x.Address) ? "" : x.Address,
Mobile= string.IsNullOrEmpty(x.Mobile) ? "" : x.Mobile,
Age= x.Age == null ? Convert.ToInt32(0) : x.Age,
};
}).ToList();
var stuList = _apiService.GetAllStudent().ToList();
model.StudentList = stuList .Select(x =>
{
return new ComponentModel()
{
ID = x.ID == null ? 0 : x.ID.Value,
Name = string.IsNullOrEmpty(x.Name) ? "" : x.Name,
Address= string.IsNullOrEmpty(x.Address) ? "" : x.Address,
Mobile= string.IsNullOrEmpty(x.Mobile) ? "" : x.Mobile,
Age= x.Age == null ? Convert.ToInt32(0) : x.Age,
};
}).ToList();
var AddExData = new List<EmployeeModel>();
AddExData.AddRange(model.EmployeeList);
AddExData.AddRange(model.StudentList);
Sunday, 1 May 2016
How to windows authentication in mvc?
Firstly, in web.config to configure-:
<system.web>
<authentication mode="Windows"></authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
After that Project property (F4 Click)
Windows Authentication Diable and Autonymous Authentication Enabled.
After that it works.
string domainUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string IsAuthentication = System.Web.HttpContext.Current.Request.IsAuthenticated.ToString();
string[] paramsLogin = domainUser.Split('\\');
string UserName = paramsLogin[1].ToString();
<system.web>
<authentication mode="Windows"></authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
After that Project property (F4 Click)
Windows Authentication Diable and Autonymous Authentication Enabled.
After that it works.
string domainUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string IsAuthentication = System.Web.HttpContext.Current.Request.IsAuthenticated.ToString();
string[] paramsLogin = domainUser.Split('\\');
string UserName = paramsLogin[1].ToString();
How to log out windows authentication in mvc?
public ActionResult LogOut()
{
HttpCookie cookie = Request.Cookies["TSWA-Last-User"];
if(User.Identity.IsAuthenticated == false || cookie == null || StringComparer.OrdinalIgnoreCase.Equals(User.Identity.Name, cookie.Value))
{
string name = string.Empty;
if(Request.IsAuthenticated)
{
name = User.Identity.Name;
}
cookie = new HttpCookie("TSWA-Last-User", name);
Response.Cookies.Set(cookie);
Response.AppendHeader("Connection", "close");
Response.StatusCode = 401; // Unauthorized;
Response.Clear();
//should probably do a redirect here to the unauthorized/failed login page
//if you know how to do this, please tap it on the comments below
Response.Write("Unauthorized. Reload the page to try again...");
Response.End();
return RedirectToAction("Index");
}
cookie = new HttpCookie("TSWA-Last-User", string.Empty)
{
Expires = DateTime.Now.AddYears(-5)
};
Response.Cookies.Set(cookie);
return RedirectToAction("Index");
}
Wednesday, 27 April 2016
How to List columns in alphabetical order?
SELECT name FROM sys.columns WHERE [object_id] = OBJECT_ID('tablename') ORDER BY name;
Subscribe to:
Posts (Atom)
