public async Task <IActionResult> Put([FromBody] CompanyUpdateViewModel campaignViewModel) { var company = _mapper.Map <Company>(campaignViewModel); await _companyService.UpdateAsync(company.CompanyId, company); return(ResponseHelper.Ok(company)); }
public async Task <ActionResult> Update(CompanyUpdateViewModel data) { if (ModelState.IsValid) { try { data.active = true; data.modifiedBy = Session["user_id"].ToString(); data.modifiedDatetime = DateTime.Now; var postTask = await client.PostAsJsonAsync("/api/Company/Update", data); if (postTask.IsSuccessStatusCode) { return(RedirectToAction("Index", "Company")); } } catch (Exception e) { ViewBag.Error = e.Message; return(View("Index", ViewBag.Error)); } } var errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); return(RedirectToActionPermanent("Index")); }
public async Task <ActionResult> UploadFiles(CompanyUpdateViewModel model) { var company = await _companyRepository.GetCompanyWithPostsAsync(CurrentCompanyId); string fileCurrentPath = Server.MapPath(company.LogoUrl); if (ModelState.IsValid) { string pic = Path.GetFileName(model.UploadFile.FileName); string path = Path.Combine(Server.MapPath("~/CompanyLogo"), CurrentCompanyId + pic); string dbPath = Url.Content("~/CompanyLogo/" + CurrentCompanyId + pic); company.LogoUrl = dbPath; bool result = await _companyRepository.UpdateCompanyAsync(company); if (result) { if (System.IO.File.Exists(fileCurrentPath)) { System.IO.File.Delete(fileCurrentPath); } model.UploadFile.SaveAs(path); } return(RedirectToAction("Index", "AdminDetails", new { message = "File uploaded successfully" })); } //Adds model state errors to a string string errors = ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)).Aggregate((a, b) => a + Environment.NewLine + b); return(RedirectToAction("UpdateCompany", "AdminDetails", new { message = errors })); }
public ActionResult Update(int CompanyId) { var model = new CompanyUpdateViewModel { Company = _companyService.GetById(CompanyId), }; return(View(model)); }
public CompanyUpdateViewModel CompanyUpdate(CompanyUpdateInputModel inputModel) { // Create your view model with the basic settings CompanyUpdateViewModel viewModel = new CompanyUpdateViewModel(true); viewModel.CompanyOperationMode = inputModel.CompanyOperationMode; viewModel.AddParent = inputModel.AddParent; // Mode 'none', will just return the information to display the screen for create mode if (inputModel.CompanyOperationMode != GlobalConstants.CRUDOperationMode.None) { // Call Talent Common to perform the relevant action TalentCompany talentCompany = new TalentCompany(); Mapper.CreateMap <CompanyUpdateInputModel, DECompany>(); talentCompany.Company = Mapper.Map <DECompany>(inputModel); talentCompany.Settings = Environment.Settings.DESettings; // Removing parent has a different route if (inputModel.CompanyOperationMode == GlobalConstants.CRUDOperationMode.Delete) { ErrorObj err = talentCompany.ParentCompanyOperations(); viewModel.Error = Data.PopulateErrorObject(err, talentCompany.ResultDataSet, talentCompany.Settings, null); } else { ErrorObj err = talentCompany.CompanyOperations(); viewModel.Error = Data.PopulateErrorObject(err, talentCompany.ResultDataSet, talentCompany.Settings, null); // We want to populate the company details when no error exists, or a Talent thrown error as we still need the company details // at that point if ((!viewModel.Error.HasError) || String.IsNullOrWhiteSpace(viewModel.Error.ReturnCode)) { viewModel.Company = Data.PopulateObjectListFromTable <CompanyModel>(talentCompany.ResultDataSet.Tables["CompanySearchResults"]).FirstOrDefault(); if (viewModel.Company != null) { viewModel.Company.CompanyNumber = talentCompany.ResultDataSet.Tables["CompanyDetails"].Rows[0]["CompanyNumber"].ToString(); } } } } // Return the list of valid agents and vat codes in the view to the caller. viewModel.VatCodeList = new VAT().retrieveVatCodes(); TalentBusinessLogic.DataTransferObjects.VAT vatLstItem = new TalentBusinessLogic.DataTransferObjects.VAT(); vatLstItem.VATCode = viewModel.GetPageText("NoVATCodeText"); vatLstItem.VATUniqueID = 0; viewModel.VatCodeList.Insert(0, vatLstItem); // Return the list of valid agents and vat codes in the view to the caller. viewModel.AgentList = new Agent().retrieveAgents(); TalentBusinessLogic.DataTransferObjects.Agent agentLstItem = new TalentBusinessLogic.DataTransferObjects.Agent(); agentLstItem.Usercode = viewModel.GetPageText("NoOwningAgentText"); viewModel.AgentList.Insert(0, agentLstItem); return(viewModel); }
public async Task <ActionResult> UpdateCompany(string message) { var company = await _companyRepository.GetCompanyWithPostsAsync(CurrentCompanyId); CompanyUpdateViewModel model = new CompanyUpdateViewModel { LoggedUser = CurrentUser, //BaseViewModel LoggedCompany = CurrentCompany, //BaseViewModel Message = message, //BaseViewModel LogoUrl = CurrentLogoUrl, //BaseViewModel CompanyName = company.CompanyName, CompanyAddress = company.CompanyAddress, CompanyPhone = company.CompanyPhone }; return(View(model)); }
public async Task <IActionResult> Edit(CompanyUpdateViewModel viewModel) { Company company = _mapper.Map <Company>(viewModel); using (HttpClient client = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(company), Encoding.UTF8, "application/json"); HttpResponseMessage responseMessage = await client.PostAsync(Startup.UrlBase + "CompanyAPI/Update", content); string jsonResponse = await responseMessage.Content.ReadAsStringAsync(); Response response = JsonConvert.DeserializeObject <Response>(jsonResponse); if (response.Success) { return(RedirectToAction("Index")); } ViewBag.Erros = response.Message; return(View()); } }
public async Task <ActionResult> Edit(string comp_id) { if (comp_id != null) { CompanyUpdateViewModel model = new CompanyUpdateViewModel(); var postTask = await client.GetAsync("/api/Company/View/?comp_id=" + comp_id); model = await postTask.Content.ReadAsAsync <CompanyUpdateViewModel>(); if (model != null) { return(View("Edit", model)); } else { CompanyIndexViewModel data = new CompanyIndexViewModel(); ViewBag.Error = "No Company Found !"; return(View("Index", data)); } } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }