public async Task <IActionResult> UpdateAsync(int id) { try { var company = _companyRepository.GetById(id); var currentuser = await _userManager.GetUserAsync(HttpContext.User); var IsSuperAdmin = User.IsInRole("SuperAdmin"); if (company == null || company.IsDeleted == true) { Response.StatusCode = 404; return(View("CompanyNotFound", id)); } else if (IsSuperAdmin || company.Id == currentuser.CompanyId) { var companyEditViewModel = new CompanyEditViewModel { Id = company.Id, Name = company.Name, ExistingPhotoPath = company.PhotoPath }; return(View(companyEditViewModel)); } return(View("NotAuthorized")); } catch (Exception ex) { _logger.LogError(ex, $"When getting the update of a company."); throw; } }
public async Task <IActionResult> GetEditCompany(string submitButton) { var company = await cService.FindCompanyByIdAsync(int.Parse(submitButton)); var vm = new CompanyEditViewModel(company, company.Offices.ToList()); return(View("EditCompany", vm)); }
private Company CreateCompany(CompanyEditViewModel viewModel) { return(new Company { Id = viewModel.Id, Title = viewModel.Title }); }
// GET: Companies/Edit/5 //public IActionResult Edit(Guid? id, Guid? empId) //{ // var emp = _context.Employers.Include(e => e.Company).ThenInclude(c => c.Employers) // .Include(e => e.AccountUser).FirstOrDefault(e => e.Id == empId); // if (empId != null) // ViewBag.EmpId = emp.Id; // if (id == null) // { // return NotFound(); // } // var company = _context.Companies.Include(c => c.City) // .Include(c => c.Employers).FirstOrDefault(m => m.Id == id); // ICollection<Models.ArreaDatabase.Employer> i = company.Employers; // ViewBag.CompanyEmployers = i; // if (company == null) // { // return NotFound(); // } // //var model = new CandidateViewModel() // //{ // // Company = company, // // EmployeeId = emp // //}; // ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", company.CityId); // return View(company); //} public IActionResult Edit(Guid?id, Guid?empId) { var emp = _context.Employers.Include(e => e.Company).ThenInclude(c => c.Employers) .Include(e => e.AccountUser).FirstOrDefault(e => e.Id == empId); if (empId != null) { ViewBag.EmpId = emp.Id; } if (id == null) { return(NotFound()); } var company = _context.Companies.Include(c => c.City) .Include(c => c.Employers) .FirstOrDefault(m => m.Id == id); var employers = company.Employers.ToList(); // ViewBag.CompanyEmployers = i; if (company == null) { return(NotFound()); } var cities = _context.Cities.Include(c => c.Companies).Select(e => new SelectListItem { Value = e.Id.ToString(), Text = e.Name }).ToList(); var model = new CompanyEditViewModel() { Id = company.Id, CompanyName = company.Name, EmployeeId = emp.Id, CompanyLogo = company.CompanyLogoUrl, CityName = company.City?.Name, Cities = cities, Description = company.Description, Email = company.Email, Facebook = company.Facebook, Site = company.Site, PhoneNumber = company.PhoneNumber, Employers = employers, Adress = company.Adress, Status = company.Status == null ? false : company.Status.Value }; // ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", company.CityId); return(View(model)); }
public async Task <IActionResult> AssignHeadquarter(string submitButton) { var id = await cService.AssignHeadquarters(int.Parse(submitButton)); var company = await cService.FindCompanyByIdAsync(id); var vm1 = new CompanyEditViewModel(company, company.Offices.ToList()); return(View("EditCompany", vm1)); }
public async Task <IActionResult> EditCompany(CompanyEditViewModel vm) { await cService.EditCompany(vm.Id, vm.Name); var company = await cService.FindCompanyByIdAsync(vm.Id); var vm1 = new CompanyEditViewModel(company, company.Offices.ToList()); return(View("EditCompany", vm1)); }
public async Task <IActionResult> AddOffice(CompanyEditViewModel vm) { await cService.AddOfficeAsync(vm.NewOfficeCountry, vm.NewOfficeCity, vm.NewOfficeStreet, vm.NewOfficeStreetNumber, vm.Id); var company = await cService.FindCompanyByIdAsync(vm.Id); var vm1 = new CompanyEditViewModel(company, company.Offices.ToList()); return(View("EditCompany", vm1)); }
public IActionResult Edit(int id) { Company company = companyService.GetCompanies().FirstOrDefault(c => c.Id == id); RegistrationData registrationData = companyService.FindRegistrationDataById(company.RegistrationDataId); CompanyViewModel companyViewModel = new CompanyViewModel(company); RegistrationDataViewModel registrationDataViewModel = new RegistrationDataViewModel(registrationData); FactAddressViewModel factAddressViewModel = new FactAddressViewModel(); ContactInfoViewModel contactInfoViewModel = new ContactInfoViewModel { CityPhone = company.ContactInfo.CityPhone, MobilePhone = company.ContactInfo.MobilePhone, Email = company.ContactInfo.Email }; Address factAddress = companyService.FindFactAddressByCompanyId(company.Id); if (factAddress != null) { factAddressViewModel.CountryId = factAddress.CountryId; factAddressViewModel.City = factAddress.City; factAddressViewModel.Street = factAddress.Street; factAddressViewModel.HouseAddress = factAddress.HouseAddress; factAddressViewModel.PostCode = factAddress.PostCode; } LegalAddressViewModel legalAddressViewModel = new LegalAddressViewModel(); Address legalAddress = companyService.FindLegalAddressByCompanyId(company.Id); if (factAddress != null) { legalAddressViewModel.CountryId = legalAddress.CountryId; legalAddressViewModel.City = legalAddress.City; legalAddressViewModel.Street = legalAddress.Street; legalAddressViewModel.HouseAddress = legalAddress.HouseAddress; legalAddressViewModel.PostCode = legalAddress.PostCode; } CompanyEditViewModel model = new CompanyEditViewModel { FactAddress = factAddressViewModel, LegalAddress = legalAddressViewModel, Company = companyViewModel, RegistrationData = registrationDataViewModel, ContactInfo = contactInfoViewModel }; model.Countries = selectListService.GetCountries(); model.LegalForms = selectListService.GetLegalForms(); model.PropertyTypes = selectListService.GetPropertyTypes(); model.Residencies = selectListService.GetResidencies(); model.TaxInspections = selectListService.GetTaxInspections(); ViewBag.CountriesForAddress = GetCountriesForAddress(); return(View(model)); }
public async Task <IActionResult> Edit(CompanyEditViewModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.companiesService.EditAsync(input.Id, input.Name, input.Bulstat, input.VatNumber, input.PhoneNumber, input.Address, input.CreatedOn); return(this.RedirectToAction("Details", "Companies", new { input.Id })); }
public string Edit([Bind(Include = "Id,Name,City")] CompanyEditViewModel companyEditViewModel) { if (ModelState.IsValid) { var company = _mapper.Map <Company>(companyEditViewModel); _repositoryCompany.Update(company); return(JsonConvert.SerializeObject(company)); } return("Failure to edit company"); }
public ModelStateDictionary ValidateCompanyEditViewModel(CompanyEditViewModel model, ModelStateDictionary ModelState) { if (model.RegistrationData.DateOfInitialRegistration > DateTime.Now) { ModelState.AddModelError("RegistrationData.DateOfInitialRegistration", "Вы ввели дату из будущего!"); } if (model.RegistrationData.DateOfRegistrationMinistryJustice > DateTime.Now) { ModelState.AddModelError("RegistrationData.DateOfRegistrationMinistryJustice", "Вы ввели дату из будущего!"); } return(ModelState); }
public async Task <IActionResult> Post([FromBody] CompanyEditViewModel vm) { if (ModelState.IsValid) { var company = new Company(); vm.ApplyTo(company); dbContext.Set <Company>().Add(company); await dbContext.SaveChangesAsync(); return(CreatedAtRoute("GetCompanyById", new { id = company.Id }, new CompanyListViewModel(company))); } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> UpdateAsync(CompanyEditViewModel editModel) { try { var currentuser = await _userManager.GetUserAsync(HttpContext.User); if (editModel.IsDeleted == true) { Response.StatusCode = 404; return(View("CompanyNotFound", editModel.Id)); } else if (User.IsInRole("SuperAdmin") || editModel.Id == currentuser.CompanyId) { if (ModelState.IsValid) { var company = _companyRepository.GetById(editModel.Id); company.Name = editModel.Name; company.UpdatedDate = DateTime.Now; company.UpdatedBy = User.Identity.Name; if (editModel.ExistingPhotoPath != null) { DeleteImage(editModel.ExistingPhotoPath); company.PhotoPath = ProcessUploadFile(editModel); } var response = _companyRepository.Update(company); if (response != null & response.Id != 0) { return(RedirectToAction("Details", new { id = editModel.Id })); } } return(View()); } return(View("NotAuthorized")); } catch (Exception ex) { _logger.LogError(ex, $"When trying to update a company."); throw; } }
public async Task <IActionResult> EditCompany(CompanyEditViewModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } int result = this.companyService.EditCompany( input.CompanyName, input.SanitizedCompanyDescription, input?.CompanyWebsite, input?.FacebookWebsite, input?.TwitterWebsite, input?.LinkedInWebsite, null, input.Id).Result; return(this.RedirectToAction("Details")); }
// GET: Company/Edit/5 public ActionResult Edit(string idUser) { // Get the candidateID with the hash code idUser Company editingCompany = this.db.Companies.Where(c => c.CompanySecondID == idUser).FirstOrDefault(); CompanyEditViewModel editVM = new CompanyEditViewModel { CompanySecondID = editingCompany.CompanySecondID, Name = editingCompany.Name, City = editingCompany.City, Address = editingCompany.Address, PhoneNumber = editingCompany.PhoneNumber, Description = editingCompany.Description, Logo = editingCompany.Logo }; ViewBag.UniqueID = idUser; return(View(editingCompany)); }
public IActionResult Edit(CompanyEditViewModel model) { validationService.ValidateCompanyEditViewModel(model, ModelState); if (ModelState.IsValid) { companyService.UpdateCompany(model); return(RedirectToAction("Index", "Company")); } model.Countries = selectListService.GetCountries(); model.Company.Logo = companyService.GetCompanyLogo(model.Company.Id); model.LegalForms = selectListService.GetLegalForms(); model.PropertyTypes = selectListService.GetPropertyTypes(); model.Residencies = selectListService.GetResidencies(); model.TaxInspections = selectListService.GetTaxInspections(); ViewBag.CountriesForAddress = GetCountriesForAddress(); return(View(model)); }
public async Task<IActionResult> Edit(int id, CompanyEditViewModel vm) { _context.Update(vm.Company); // Wipe out their previous availabilities _context.RemoveRange(_context.CompanyAvailability.Where(c => c.CompanyId == id)); // Build new availabilities based on what they selected var newAvailabilities = vm.TimeSlotIds.Select(t => new CompanyAvailability() { CompanyId = id, TimeSlotId = t }).ToList(); _context.CompanyAvailability.AddRange(newAvailabilities); await _context.SaveChangesAsync(); return RedirectToAction("Index"); }
public ActionResult EditCompanyAll() { AccountController ac = new AccountController(); string realName = ac.GetRealName(User.Identity.Name); var model = new List <CompanyEditViewModel>(); //把未知的和自己的客户列出去,未知的排在前面。然后用radio的方式给展示 var q = (from p in db.OtaCompany where p.SalesUserName == "未知" || p.SalesUserName == realName orderby p.CreateTime, p.SalesUserName select p).Take(50); foreach (OtaCompany item in q) { CompanyEditViewModel editItem = new CompanyEditViewModel(); editItem.BusinessRange = item.BusinessRange; editItem.BusinessStatus = item.BusinessStatus; editItem.CompanyName = item.CompanyName; editItem.Id = item.Id; editItem.SalesUserName = item.SalesUserName; model.Add(editItem); } var BusinessRangeList = (from p in db.ParamDict where p.ParamName == "业务类型" select p.SubItemName).ToList(); ViewData["BusinessRangeList"] = BusinessRangeList; var BusinessStatusList = (from p in db.ParamDict where p.ParamName == "业务状态" select p.SubItemName).ToList(); ViewData["BusinessStatusList"] = BusinessStatusList; List <string> allRealNames = ac.GetAllRealName(); allRealNames.Remove("admin"); allRealNames.Remove("郑亚军"); allRealNames.Add("未知"); ViewData["SalesNameList"] = allRealNames; return(View(model)); }
public async Task <IActionResult> Put(int id, [FromBody] CompanyEditViewModel vm) { var company = await dbContext.Set <Company>().FindAsync(id); if (company == null) { return(NotFound()); } if (ModelState.IsValid) { vm.ApplyTo(company); await dbContext.SaveChangesAsync(); return(AcceptedAtRoute("GetCompanyById", new { id = company.Id }, new CompanyListViewModel(company))); } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> EditCompany(CompanyEditViewModel input) { var user = await this.userManager.GetUserAsync(this.User); if (!this.ModelState.IsValid) { return(this.View(input)); } var img = await this.fileService.UploadImageFileAsync(input.PictureFile, user.Id, "CompanyLogo"); int result = this.companyService.EditCompany( input.CompanyName, input.SanitizedCompanyDescription, input?.CompanyWebsite, input?.FacebookWebsite, input?.TwitterWebsite, input?.LinkedInWebsite, img?.SecureUri?.ToString(), input.Id).Result; return(this.RedirectToAction("Index")); }
// GET: Companies/Edit/5 public async Task<IActionResult> Edit(int? id) { if (id == null) { return NotFound(); } var availableTimes = _context.CompanyAvailability.Where(c => c.CompanyId == id).Select(c => c.TimeSlot).ToList(); var vm = new CompanyEditViewModel() { Company = await _context.Company.FindAsync(id), TimeSlots = await _context.TimeSlot.OrderBy(t => t.StartTime).Select(time => new SelectListItem() { Text = $"{time.StartTime.ToString("hh:mm tt")} - {time.EndTime.ToString("hh:mm tt")}", Value = time.Id.ToString(), Selected = availableTimes.Contains(time) }).ToListAsync() }; return View(vm); }
public ActionResult Add(CompanyEditViewModel cevm) { int? tc = 0; int id1 = 0; int tc1 = 0; DateTime?validto = null; IEnumerable <ClassificatorValue> cv = _classificatorValueRepository.FindByValue("Companies"); foreach (var obj in cv) { tc = obj.Legal; id1 = obj.Id; validto = obj.ValidTo; } if (validto == null && tc == null) { return(Json(new { IsSucceed = false, Msg = "licence error", Count = 0 })); } else { con.Open(); SqlCommand cmd = new SqlCommand("select count(distinct CompanyId) from users where IsDeleted=0 and CompanyId is not null and id in (select UserId from uSERROLES where IsDeleted=0 and RoleId in (select id from Roles where IsDeleted=0 and RoleTypeId=3))", con); tc1 = Convert.ToInt32(cmd.ExecuteScalar()); con.Close(); int remaining = Convert.ToInt32(tc) - tc1; remaining = remaining < 0 ? 0 : remaining; if (remaining > 0 && validto > DateTime.Now) { int id = 0; string err = string.Empty; if (cevm.Company.CompanyBuildingItems.Any(x => x.BuildingId == null)) { ModelState.AddModelError("Company.CompanyBuildingItems", ViewResources.SharedStrings.CompaniesEmptyBuildingSelected); } if (cevm.Company.CompanyBuildingItems.Any(x => x.BuildingId != null && !x.CompanyFloors.Any(cf => cf.IsSelected))) { ModelState.AddModelError("Company.CompanyBuildingItems", ViewResources.SharedStrings.CompaniesNoBuildingSelectedMessage); } var build_ids = GetUserBuildings(_buildingRepository, _userRepository); if (build_ids.Any(x => cevm.Company.CompanyBuildingItems.Where(cb => cb.BuildingId == x).Count() > 1)) { ModelState.AddModelError("Company.CompanyBuildingItems", ViewResources.SharedStrings.CompaniesEqualBildingsErrorMessage); } var building_items = new List <SelectListItem>(); Mapper.Map(_buildingRepository.FindAll().Where(x => build_ids.Contains(x.Id)), building_items); foreach (var cbi in cevm.Company.CompanyBuildingItems) { cbi.BuildingItems = building_items; } if (ModelState.IsValid) { try { IEnumerable <CompanyBuildingDto> company_buildings = GetSelectedCompanyBuildings(cevm.Company); id = _companyService.CreateCompany(cevm.Company.Name, cevm.Company.Comment, cevm.Company.IsCanUseOwnCards, HostName, company_buildings); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); err = ex.Message; } } if (id < 0) { return(Json(new { IsSucceed = false })); } else { var complist = _companyRepository.FindAll().Where(x => x.IsDeleted == false && x.Active == true && x.ParentId == null).OrderBy(y => y.Name).ToList(); cevm.CompanyItems = complist; return(Json(new { IsSucceed = ModelState.IsValid, Id = id, Msg = ModelState.IsValid ? ViewResources.SharedStrings.DataSavingMessage : err, viewData = ModelState.IsValid ? string.Empty : this.RenderPartialView("Create", cevm) })); } } else { return(Json(new { IsSucceed = false, Msg = "licence error", Count = tc })); } } }
public async Task <IActionResult> Edit(CompanyEditViewModel model, IFormFile Image) { var companyUpdate = _context.Companies.Include(c => c.City) .Include(c => c.Employers).FirstOrDefault(m => m.Id == model.Id); var emplCompany = companyUpdate.Employers.FirstOrDefault(e => e.Id == model.EmployeeId); var city = _context.Cities.Include(c => c.Companies) .FirstOrDefault(c => c.Id == model.CityId); //if (ModelState.IsValid) { Search_Work.Models.ArreaDatabase.Employer emp = null; try { if (Image != null) { string name = Image.FileName; string path = $"/files/{name}"; string serverPath = $"{_environment.WebRootPath}{path}"; FileStream fs = new FileStream(serverPath, FileMode.Create, FileAccess.Write); await Image.CopyToAsync(fs); fs.Close(); companyUpdate.CompanyLogoUrl = path; } emp = _context.Employers.Include(e => e.Company) .Include(e => e.AccountUser).FirstOrDefault(e => e.Id == model.EmployeeId); // if(companyEmployers == null) if (!companyUpdate.Employers.Contains(emp)) { companyUpdate.Employers.Add(emp); } companyUpdate.Name = model.CompanyName; companyUpdate.City = city; //companyUpdate.Requirements = model.Re companyUpdate.Description = model.Description; companyUpdate.PhoneNumber = model.PhoneNumber; companyUpdate.Email = model.Email; companyUpdate.Site = model.Site; companyUpdate.Facebook = model.Facebook; companyUpdate.Adress = model.Adress; // companyUpdate.Employers = model.Employers; if ((companyUpdate.Status == false && model.Status == true) || (companyUpdate.Status == true && model.Status == false)) { companyUpdate.Status = model.Status; } _context.Companies.Update(companyUpdate); _context.SaveChanges(); return(RedirectToAction(nameof(Details), new { id = companyUpdate.Id, empId = emplCompany.Id })); } catch (DbUpdateConcurrencyException) { if (!CompanyExists(companyUpdate.Id)) { return(NotFound()); } else { //return RedirectToAction("Logout", "Account"); return(RedirectToAction(nameof(Details), new { id = companyUpdate.Id, empId = emplCompany.Id })); } } //return RedirectToAction(nameof(Details), new { id = company.Id, empId = empId }); } // return RedirectToAction(nameof(Details), new { id = companyUpdate.Id, empId = emplCompany.Id }); }
public ActionResult Update(CompanyEditViewModel cevm) { var tcevm = CreateViewModel <CompanyEditViewModel>(); string err = string.Empty; if (cevm.Company.CompanyBuildingItems.Any(x => x.BuildingId == null)) { ModelState.AddModelError("Company.CompanyBuildingItems", ViewResources.SharedStrings.CompaniesEmptyBuildingSelected); } if (cevm.Company.CompanyBuildingItems.Any(x => x.BuildingId != null && !x.CompanyFloors.Any(cf => cf.IsSelected))) { ModelState.AddModelError("Company.CompanyBuildingItems", ViewResources.SharedStrings.CompaniesNoBuildingSelectedMessage); } var build_ids = GetUserBuildings(_buildingRepository, _userRepository); if (build_ids.Any(x => cevm.Company.CompanyBuildingItems.Where(cb => cb.BuildingId == x).Count() > 1)) { ModelState.AddModelError("Company.CompanyBuildingItems", ViewResources.SharedStrings.CompaniesEqualBildingsErrorMessage); } var building_items = new List <SelectListItem>(); Mapper.Map(_buildingRepository.FindAll().Where(x => build_ids.Contains(x.Id)), building_items); foreach (var cbi in cevm.Company.CompanyBuildingItems) { cbi.BuildingItems = building_items; } if (ModelState.IsValid) { try { IEnumerable <CompanyBuildingDto> company_buildings = GetSelectedCompanyBuildings(cevm.Company); _companyService.UpdateCompany(cevm.Company.Id.Value, cevm.Company.Name, cevm.Company.Comment, cevm.Company.IsCanUseOwnCards, HostName, company_buildings); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); err = ex.Message; } } else { tcevm.Company = cevm.Company; } if (ModelState.IsValid == false) { var complist = _companyRepository.FindAll().Where(x => x.IsDeleted == false && x.Active == true && x.ParentId == null && x.Id != cevm.Company.Id).OrderBy(y => y.Name).ToList(); tcevm.CompanyItems = complist; } return(Json(new { IsSucceed = ModelState.IsValid, Id = cevm.Company.Id, Msg = ModelState.IsValid ? ViewResources.SharedStrings.DataSavingMessage : err, viewData = ModelState.IsValid ? string.Empty : this.RenderPartialView("Edit", tcevm) })); }