public string DeleteClient(AdminViewModel Model) { string msg; try { if (ModelState.IsValid) { var enditedValue = new LMS_Datas.Admin { Active = false, AdminId = Model.AdminId, Address = Model.Address, EmailId = Model.EmailId, dob = Model.dob }; entity.Entry(enditedValue).State = EntityState.Modified; entity.SaveChanges(); msg = "Delete Successfully"; } else { msg = "Validation data not successfully"; } } catch (Exception e1) { msg = "Validation data not successfully"; } return(msg); }
// Admin is Client Here public string EditClient(AdminViewModel Model) { string msgClient; try { if (ModelState.IsValid) { var enditedAdminValue = new LMS_Datas.Admin { Active = true, AdminId = Model.AdminId, Address = Model.Address, EmailId = Model.EmailId, dob = Model.dob, Name = Model.ClientName, MobileNo = Model.MobileNo }; entity.Admins.Attach(enditedAdminValue); entity.Entry(enditedAdminValue).Property(x => x.cityId).IsModified = false; entity.Entry(enditedAdminValue).Property(x => x.stateId).IsModified = false; entity.Entry(enditedAdminValue).Property(x => x.dob).IsModified = false; entity.Entry(enditedAdminValue).Property(x => x.gender).IsModified = false; entity.Entry(enditedAdminValue).Property(x => x.countryId).IsModified = false; entity.Entry(enditedAdminValue).Property(x => x.Name).IsModified = true; entity.Entry(enditedAdminValue).Property(x => x.EmailId).IsModified = true; entity.Entry(enditedAdminValue).Property(x => x.MobileNo).IsModified = true; //entity.Entry(enditedValue).State = EntityState.Modified; entity.SaveChanges(); int?loginid = (from loginId in entity.Logins where loginId.UserId == Model.AdminId select loginId.UserId).FirstOrDefault(); var enditedAdminLoginValue = new Login { UserName = Model.UserName, Password = Model.Password, UserId = loginid, Activate = "true" }; entity.Logins.Attach(enditedAdminLoginValue); entity.Entry(enditedAdminLoginValue).State = EntityState.Modified; entity.SaveChanges(); msgClient = "Saved Successfully"; } else { msgClient = "Validation data not successfully"; } } catch (Exception ex) { msgClient = "Error in Retriving Data"; } return(msgClient); }
public ActionResult Index(AdminViewModel model, FormCollection form, HttpPostedFileBase files) { try { if (ModelState.IsValid) { string statusDDLValue = form["Statusddl"].ToString(); string genderDDLValue = form["genderddl"].ToString(); //var clientId= entity.InsertUpdateSelectAdmin(0, model.name, model.Address, model.MobileNo, model.EmailId, genderDDLValue, model.dob, model.countryId, model.stateId, model.cityId, 1, ); using (var context = new LoyaltyManagementSystemEntities()) { // Client is Admin var admin = new LMS_Datas.Admin() { Name = model.ClientName, Address = model.Address, dob = model.dob, EmailId = model.EmailId, MobileNo = model.MobileNo, gender = genderDDLValue, countryId = model.countryId, stateId = model.stateId, cityId = model.cityId, Active = Boolean.Parse(statusDDLValue) }; context.Admins.Add(admin); //context.ClientDetails.Add(clientDetails); //etc add your other classes context.SaveChanges(); admin.AdminId = admin.AdminId; var adminLogin = new LMS_Datas.Login() { LoginId = admin.AdminId, UserName = model.UserName, Role = "Client", Password = model.Password }; context.Logins.Add(adminLogin); context.SaveChanges(); if (files.FileName != null) { var ext = Path.GetExtension(files.FileName); string myfile = admin.AdminId + ext; var path = Path.Combine(Server.MapPath("~/Images/ClientProfile"), myfile); files.SaveAs(path); } } ViewBag.CountryDd = new SelectList(entity.countries.Where(models => models.Active == true), "countryId", "countryName"); ViewBag.alert = "Success"; return(View()); } ViewBag.CountryDd = new SelectList(entity.countries.Where(models => models.Active == true), "countryId", "countryName"); ViewBag.alert = "Error"; return(View(model)); } catch (Exception e1) { ViewBag.CountryDd = new SelectList(entity.countries.Where(models => models.Active == true), "countryId", "countryName"); ViewBag.alert = "Error"; return(View()); } }