public ActionResult RegisterCompany(RegisterInformationModel bdsInformationModel) { bdsInformationModel.Status = false; try { bdsInformationModel.Status = false; if (Session["Captcha"] == null || Session["Captcha"].ToString() != bdsInformationModel.tblCaptCha.Captcha) { CaptCha cap = new CaptCha(); BDSNew BDSNew = new BDSNew(); var dataCity = (from data in db.States join datatext in db.StateTexts on data.name_id equals datatext.id where datatext.language_id == "vi" && data.state_id != 59 && data.state_id != 28 select new GeoModel { CityId = data.state_id, CityName = datatext.text }).ToList(); dataCity.Insert(0, new GeoModel { CityId = 0, CityName = "Chọn thành/phố" }); dataCity.Insert(1, new GeoModel { CityId = 59, CityName = "TP.Hồ Chí Minh" }); dataCity.Insert(2, new GeoModel { CityId = 28, CityName = "TP.Hà Nội" }); var dataDist = (from data in db.Districts join datatext in db.DistrictTexts on data.name_id equals datatext.id where datatext.language_id == "vi" select new GeoModel { DistId = data.district_id, DistName = datatext.text }).ToList(); dataDist.Insert(0, new GeoModel { DistId = 0, DistName = "Chọn quận/huyện" }); bdsInformationModel = new RegisterInformationModel { ListBDSScopes = db.BDSScopes.ToList(), ListMarriea = db.BDSMarriages.ToList(), ListSalary = db.BDSSalaries.ToList(), ListDucation = db.BDSEducations.ToList(), ListBDSCareer = db.BDSCareers.ToList(), ListTimework = db.BDSTimeWorks.ToList(), ListBDSLanguage = db.BDSLanguages.ToList(), ListBDSNewsType = db.BDSNewsTypes.OrderBy(x => x.Order).ToList(), ListGeoModel = dataCity.ToList(), ListGeoDisModel = dataCity.ToList(), tblCaptCha = cap, tblBDSNew = BDSNew, ListBDSEmployerInformation = db.BDSEmployerInformations.ToList(), ListBDSPersonalInformation = db.BDSPersonalInformations.ToList(), ListBdsAdcount = db.BDSAccounts.ToList(), ListBDSEmper = db.BDSEmpers.ToList(), Status = false, Msg = "Mã an toàn không đúng. Vui lòng nhập lại !" }; } else { bdsInformationModel.TblBdsAdcount.CreateDate = DateTime.Now; bdsInformationModel.TblBdsAdcount.CreateUser = 1; bdsInformationModel.TblBdsAdcount.Active = 1; bdsInformationModel.TblBdsAdcount.Money = 0; bdsInformationModel.TblBdsAdcount.Point = 0; bdsInformationModel.TblBdsAdcount.MailActive = 0; bdsInformationModel.TblBdsAdcount.Token = Guid.NewGuid().ToString(); db.Entry(bdsInformationModel.TblBdsAdcount).State = EntityState.Added; db.SaveChanges(); BDSEmployerInformation tblemployee = new BDSEmployerInformation(); bdsInformationModel.TblBDSEmployerInformation.IdAccount = bdsInformationModel.TblBdsAdcount.ID; bdsInformationModel.TblBDSEmployerInformation.Active = 1; bdsInformationModel.TblBDSEmployerInformation.CreateDate = DateTime.Now; bdsInformationModel.TblBDSEmployerInformation.CreateUser = 1; bdsInformationModel.TblBDSEmployerInformation.ModifiedDate = DateTime.Now; bdsInformationModel.TblBDSEmployerInformation.ModifiedUser = 1; bdsInformationModel.TblBDSEmployerInformation.Featured = 0; bdsInformationModel.TblBDSEmployerInformation.PhoneContact = bdsInformationModel.TblBDSEmployerInformation.Phone; bdsInformationModel.TblBDSEmployerInformation.DistrictContact = bdsInformationModel.TblBDSEmployerInformation.District; bdsInformationModel.TblBDSEmployerInformation.City = bdsInformationModel.TblBDSEmployerInformation.City; bdsInformationModel.TblBDSEmployerInformation.AddressContact = bdsInformationModel.TblBDSEmployerInformation.Address; bdsInformationModel.TblBDSEmployerInformation.EmailContact = bdsInformationModel.TblBdsAdcount.Email; bdsInformationModel.TblBDSEmployerInformation.TypeContact = 1; bdsInformationModel.TblBDSEmployerInformation.IdAccount = bdsInformationModel.TblBdsAdcount.ID; db.Entry(bdsInformationModel.TblBDSEmployerInformation).State = EntityState.Added; db.SaveChanges(); bdsInformationModel.Status = true; bdsInformationModel.Msg = "Tạo tài khoản thành công.Vui lòng kiểm tra email để kích hoạt tài khoản!"; SendTemplateEmail(bdsInformationModel.TblBdsAdcount.Email, bdsInformationModel.TblBdsAdcount.Email, bdsInformationModel.TblBdsAdcount.Token, "Email kích hoạt tài khoản", 1); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in State \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } bdsInformationModel.Status = false; bdsInformationModel.Msg = "Tạo tài khoản thất bại!"; } return(Json(bdsInformationModel)); }
public ActionResult ManagementAcountEmployee(RegisterInformationModel register) { if (Session["IdUser"] == null && Session["EmailUser"] == null) { return(RedirectToAction("LoginForm", "Login")); } if (Session["IdUserEmployee"] != null) { var idAcount = int.Parse(Session["IdUser"].ToString()); BDSAccount TblBdsAdcount = db.BDSAccounts.Find(register.TblBdsAdcount.ID); TblBdsAdcount.Email = register.TblBdsAdcount.Email; db.Entry(TblBdsAdcount).State = EntityState.Modified; db.SaveChanges(); var idEmployee = db.BDSEmployerInformations.FirstOrDefault(x => x.IdAccount == register.TblBdsAdcount.ID); if (idEmployee != null) { BDSEmployerInformation TblBDSEmployerInformation = db.BDSEmployerInformations.Find(idEmployee.ID); TblBDSEmployerInformation.Name = register.TblBDSEmployerInformation.Name; TblBDSEmployerInformation.Address = register.TblBDSEmployerInformation.Address; TblBDSEmployerInformation.Phone = register.TblBDSEmployerInformation.Phone; TblBDSEmployerInformation.City = register.TblBDSEmployerInformation.City; TblBDSEmployerInformation.Scope = register.TblBDSEmployerInformation.Scope; TblBDSEmployerInformation.Description = register.TblBDSEmployerInformation.Description; TblBDSEmployerInformation.UrlImage = register.TblBDSEmployerInformation.UrlImage; TblBDSEmployerInformation.Fax = register.TblBDSEmployerInformation.Fax; TblBDSEmployerInformation.WebSite = register.TblBDSEmployerInformation.WebSite; TblBDSEmployerInformation.NameContact = register.TblBDSEmployerInformation.NameContact; TblBDSEmployerInformation.EmailContact = register.TblBDSEmployerInformation.EmailContact; TblBDSEmployerInformation.AddressContact = register.TblBDSEmployerInformation.AddressContact; TblBDSEmployerInformation.PhoneContact = register.TblBDSEmployerInformation.PhoneContact; TblBDSEmployerInformation.TypeContact = register.TblBDSEmployerInformation.TypeContact; db.Entry(TblBDSEmployerInformation).State = EntityState.Modified; db.SaveChanges(); } var dataCity = (from data in db.States join datatext in db.StateTexts on data.name_id equals datatext.id where datatext.language_id == "vi" && data.state_id != 59 && data.state_id != 28 select new GeoModel { CityId = data.state_id, CityName = datatext.text }).ToList(); dataCity.Insert(0, new GeoModel { CityId = 0, CityName = "Chọn thành/phố" }); dataCity.Insert(1, new GeoModel { CityId = 59, CityName = "TP.Hồ Chí Minh" }); dataCity.Insert(2, new GeoModel { CityId = 28, CityName = "TP.Hà Nội" }); var dataDist = (from data in db.Districts join datatext in db.DistrictTexts on data.name_id equals datatext.id where datatext.language_id == "vi" select new GeoModel { DistId = data.district_id, DistName = datatext.text }).ToList(); dataCity.Insert(0, new GeoModel { CityId = 0, CityName = "Chọn thành/phố" }); dataDist.Insert(0, new GeoModel { DistId = 0, DistName = "Chọn quận/huyện" }); CaptCha cap = new CaptCha(); BDSNew BDSNew = new BDSNew(); var register1 = new RegisterInformationModel { ListBDSScopes = db.BDSScopes.ToList(), ListMarriea = db.BDSMarriages.ToList(), ListSalary = db.BDSSalaries.ToList(), ListDucation = db.BDSEducations.ToList(), ListBDSCareer = db.BDSCareers.ToList(), ListTimework = db.BDSTimeWorks.ToList(), ListBDSLanguage = db.BDSLanguages.ToList(), ListBDSNewsType = db.BDSNewsTypes.OrderBy(x => x.Order).ToList(), ListGeoModel = dataCity.ToList(), ListGeoDisModel = dataDist.ToList(), tblCaptCha = cap, tblBDSNew = BDSNew, TblBDSEmployerInformation = db.BDSEmployerInformations.FirstOrDefault(x => x.IdAccount == idAcount), TblBDSPersonalInformation = db.BDSPersonalInformations.FirstOrDefault(x => x.IdAccount == idAcount), TblBdsAdcount = db.BDSAccounts.FirstOrDefault(x => x.ID == idAcount), ListBDSEmper = db.BDSEmpers.ToList() }; return(View(register1)); } if (Session["IdUserPer"] != null) { var idAcount = int.Parse(Session["IdUser"].ToString()); BDSAccount TblBdsAdcount = db.BDSAccounts.Find(idAcount); TblBdsAdcount.Email = register.TblBdsAdcount.Email; db.Entry(TblBdsAdcount).State = EntityState.Modified; db.SaveChanges(); var idEmployee = db.BDSPersonalInformations.FirstOrDefault(x => x.IdAccount == idAcount); if (idEmployee != null) { BDSPersonalInformation BDSPersonalInformation = db.BDSPersonalInformations.Find(idEmployee.ID); BDSPersonalInformation.Name = register.TblBDSPersonalInformation.Name; BDSPersonalInformation.TemporaryAddress = register.TblBDSPersonalInformation.TemporaryAddress; BDSPersonalInformation.Province = register.TblBDSPersonalInformation.Province; BDSPersonalInformation.PermanentAddress = register.TblBDSPersonalInformation.PermanentAddress; BDSPersonalInformation.Phone = register.TblBDSPersonalInformation.Phone; // BDSPersonalInformation.City = register.TblBDSPersonalInformation.City; BDSPersonalInformation.Description = register.TblBDSPersonalInformation.Description; BDSPersonalInformation.UrlImage = register.TblBDSPersonalInformation.UrlImage; BDSPersonalInformation.Birthday = register.TblBDSPersonalInformation.Birthday; BDSPersonalInformation.Sex = register.TblBDSPersonalInformation.Sex; // BDSPersonalInformation.City= register.TblBDSPersonalInformation.City; // BDSPersonalInformation.District = register.TblBDSPersonalInformation.District; BDSPersonalInformation.MaritalStatus = register.TblBDSPersonalInformation.MaritalStatus; // BDSPersonalInformation.Salary = register.TblBDSPersonalInformation.Salary; // BDSPersonalInformation.Experience = register.TblBDSPersonalInformation.Experience; // BDSPersonalInformation.Education = register.TblBDSPersonalInformation.Education; // BDSPersonalInformation.IdLoaiNghe = register.TblBDSPersonalInformation.IdLoaiNghe; // BDSPersonalInformation.ProfessionalExperience = register.TblBDSPersonalInformation.ProfessionalExperience; db.Entry(BDSPersonalInformation).State = EntityState.Modified; db.SaveChanges(); } var dataCity = (from data in db.States join datatext in db.StateTexts on data.name_id equals datatext.id where datatext.language_id == "vi" && data.state_id != 59 && data.state_id != 28 select new GeoModel { CityId = data.state_id, CityName = datatext.text }).ToList(); dataCity.Insert(0, new GeoModel { CityId = 0, CityName = "Chọn thành/phố" }); dataCity.Insert(1, new GeoModel { CityId = 59, CityName = "TP.Hồ Chí Minh" }); dataCity.Insert(2, new GeoModel { CityId = 28, CityName = "TP.Hà Nội" }); var dataDist = (from data in db.Districts join datatext in db.DistrictTexts on data.name_id equals datatext.id where datatext.language_id == "vi" select new GeoModel { DistId = data.district_id, DistName = datatext.text }).ToList(); dataDist.Insert(0, new GeoModel { DistId = 0, DistName = "Chọn quận/huyện" }); CaptCha cap = new CaptCha(); BDSNew BDSNew = new BDSNew(); var register1 = new RegisterInformationModel { ListBDSScopes = db.BDSScopes.ToList(), ListMarriea = db.BDSMarriages.ToList(), ListSalary = db.BDSSalaries.ToList(), ListDucation = db.BDSEducations.ToList(), ListBDSCareer = db.BDSCareers.ToList(), ListTimework = db.BDSTimeWorks.ToList(), ListBDSLanguage = db.BDSLanguages.ToList(), ListBDSNewsType = db.BDSNewsTypes.OrderBy(x => x.Order).ToList(), ListGeoModel = dataCity.ToList(), ListGeoDisModel = dataDist.ToList(), tblCaptCha = cap, tblBDSNew = BDSNew, TblBDSEmployerInformation = db.BDSEmployerInformations.FirstOrDefault(x => x.IdAccount == idAcount), TblBDSPersonalInformation = db.BDSPersonalInformations.FirstOrDefault(x => x.IdAccount == idAcount), TblBdsAdcount = db.BDSAccounts.FirstOrDefault(x => x.ID == idAcount), ListBDSEmper = db.BDSEmpers.ToList() }; return(View(register1)); } return(null); }