public async Task <IActionResult> Create(CreatePersonViewModel model) { if (ModelState.IsValid) { int id = Int32.MaxValue; // if model has image, handle it: if (model.PersonImage != null) { // scale & encode to base64 string img = await ImageService.GetJpegBase64String(model.PersonImage); if (!String.IsNullOrEmpty(img)) { id = await _svc.AddAsync(model.FullName, model.JobTitle, img); } else { ModelState.AddModelError("PersonImage", "Please upload " + string.Join(", ", _config.AllowedImageFileExtensions) + " files only."); return(View(model)); } } // put default images else { id = await _svc.AddAsync(model.FullName, model.JobTitle, defaultBase64profile); } return(RedirectToAction("Details", new { id })); } return(View(model)); }
public async Task <ActionResult> Add(PeopleViewModel peopleViewModel) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } await _peopleService.AddAsync(_mapper.Map <People>(peopleViewModel)); return(CustomResponse(peopleViewModel)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Birthday,IsEmploye,IsChief,UserId,CompanyId")] Person person) { if (ModelState.IsValid) { await _peopleService.AddAsync(person); return(RedirectToAction(nameof(Index))); } await SetCommonViewBag(null); ViewBag.Roles = new SelectList(_peopleService.GetRolesIds(), "Id", "Name"); return(View(person)); }
public async Task <Option <CsvReport, Error> > PeopleByJson(IFormFile file) { var json = await file.ReadAsStringAsync(); try { var peopleDto = DeserializeObject <IEnumerable <PersonOnboardingModel> >(json); var resultCollection = new List <Option <Person, Error> >(); foreach (var model in peopleDto) { var person = new Person { FirstName = model.FirstName, LastName = model.LastName, MiddleNameInitial = model.MiddleInitial, Gender = model.Gender, Birthdate = model.Birthday, Phone = model.Phone, Email = model.Email }; resultCollection.Add(await _peopleService.AddAsync(person)); } var successfullyAddPeopleNames = resultCollection .Values() .Select(person => new OnboardingCsvReportModel($"{person.FullName} successfully added!")) .ToList(); var unsuccessfullyAddPeopleErrs = resultCollection .Exceptions() .Select(error => new OnboardingCsvReportModel(string.Join(", ", error.Messages))) .ToList(); var reportName = $"people-onboarding-{file.Name}-{DateTime.Now.Date}"; return(PrepareReport(successfullyAddPeopleNames, unsuccessfullyAddPeopleErrs, reportName) .Some <CsvReport, Error>()); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(Option.None <CsvReport, Error>( new Error("Something went wrong while deserializing the file! " + "Please, check for any mistakes."))); } }