public IActionResult AddJob(ClientJobViewModel model) { if (ModelState.IsValid) { if (model.businessstreams.Count == 0) { model.businessstreams = new List <SelectListItem>(); model.businessstreams.Add(new SelectListItem { Value = "", Text = "-- 業界選択 --" }); var businessstreams = _businessRepository.GetAll(); foreach (var BusinessStrem in businessstreams) { model.businessstreams.Add(new SelectListItem { Value = Convert.ToString(BusinessStrem.Id), Text = BusinessStrem.Name_jp }); } } var jobcategory = _jobCategoryRepository.GetById(Convert.ToInt32(model.JobCategoryId)); var job = new Job(); job.JobCategory = jobcategory; job.JobTitle = jobcategory.CategoryName; job.ContractType_Text = model.ContractType; job.Salary_Hourly = model.Salary_Hourly; job.Salary_Monthly = model.Salary_Monthly; job.WorkingdaysPerweek = model.WorkingDaysPerWeek; job.Workinghour = model.Workinghour; job.Role = model.JobTitle; //here job title and role is same job.JapaneseLevel_Text = model.JapaneseLevel; job.Transporationfee = model.TransportationFee; job.WorkLocationAddress = model.Address; job.Client = _clientRepository.GetById(model.ClientID); job.CompanyName = job.Client.CompanyName; job.BusinessStream = _businessRepository.GetById(model.BusinessstreamID); job.NeededStaff = model.NeededStaff; job.provinceName = model.ProvinceName; //string workingTime = $"{model.WorkStartTime}-{model.WorkEndTime}"; job.Status = model.Status; job.StartWorkingTime = model.WorkStartTime; job.EndWorkingTime = model.WorkEndTime; //string requiredAge = $"{model.MinAge}-{model.MaxAge}"; //job.RequiredAge = requiredAge; job.MinAge = model.MinAge; job.MaxAge = model.MaxAge; job.PostDate = DateTime.Now; string postalCodeValue = model.PostalAddrss1 + "-" + model.PostalAddrss2; var postalCode = _postalCodeRepository.Find(x => x.Code == postalCodeValue).FirstOrDefault(); job.PostalCode = postalCode; job.WorkLocationAddress = model.Address; job.ContractType = new ContractType(); job.JapaneseLevel = new JapaneseLevel(); int result = _jobsRepository.Create(job); if (result > 0) { return(Redirect("~/Clients")); } else { ViewData["error"] = "Error in saving data"; return(View(model)); } } else { ViewBag.ErrorMsg = "Validation Failed"; return(View(model)); } }
public async Task <IActionResult> EditProfile(ClientEditViewModel model) { if (ModelState.IsValid) { var user = _userManager.GetUserAsync(HttpContext.User).Result; model.Provinces = await _autoFillService.AddProvinceListAsync(); int postalId = 0; string postalcode = model.PostalAddrss1 + "-" + model.PostalAddrss2; var postalcodeList = _postalCodeRepository.Find(x => x.Code == postalcode); foreach (var postalcodeobj in postalcodeList) { postalId = postalcodeobj.Id; } Client client = _clientRepository.GetClientByUserId(user.Id); //client.Id = model.ClientID; client.CompanyName = model.CompanyName; client.ContactNumber = model.PhoneNumber; client.ContactPerson = model.ContactPerson; client.WebsiteUrl = model.WebsiteUrl; client.PostalCodeID = postalId; client.Address = model.Address; //client.ApplicationUser = user; if (model.Files != null) { //string webrootpath = _hostingEnvironment.WebRootPath; string folderpath = Path.Combine(_hostingEnvironment.WebRootPath, "assets", "img", "companies", client.Id.ToString()); string virtualPath = Path.Combine("..", "assets", "img", "companies", client.Id.ToString()); if (!Directory.Exists(folderpath)) { Directory.CreateDirectory(folderpath); } string filePath = Path.Combine(folderpath, $"companyimage.png"); string virtualFilePath = Path.Combine(virtualPath, $"companyimage.png"); using (Image img = Image.FromStream(model.Files[0].OpenReadStream())) { var resizedImg = img.Resize(250, 250); resizedImg.SaveIntoDisk(filePath); //save image path into comapnyimage object IEnumerable <CompanyImage> companyImages = await _companyImage.FindByAsyn(x => x.ClientId == model.ClientID); CompanyImage companyImage = new CompanyImage(); if (companyImages.Count() < 1) { companyImage.ImagePath = virtualFilePath; companyImage.Client = client; await _companyImage.AddAsyn(companyImage); } else { companyImage = companyImages.FirstOrDefault(); companyImage.ImagePath = virtualFilePath; _companyImage.Update(companyImage); } } } var result = _clientRepository.Update(client); user.FirstName = model.FirstName; user.LastName = model.LastName; user.PhoneNumber = model.PhoneNumber; // await _companyImage.SaveAsync(); //Saving company image //long size = model.Files.Sum(f => f.Length); //End of company save image if (result > 0) { ModelState.Clear(); ViewData["success"] = "データが保存されました"; } else { //foreach (var error in ModelState) //{ // ModelState.AddModelError(string.Empty, error.Description); //} ViewData["error"] = "データ保存の際にエラーが発生しました"; } } return(View(model)); }