public async Task UpdateEmployeeImage(EmployeeImageViewModel model) { if (model.EmployeeImage != null) { var employeeImage = new EmployeeImageModel { ImageId = model.ImageId, EmployeeId = model.EmployeeId, }; using (var memoryStream = new MemoryStream()) { await model.EmployeeImage.CopyToAsync(memoryStream); employeeImage.Images = memoryStream.ToArray(); } var existingImage = await _employeeImageService.ExistsAsync(model.EmployeeId); if (existingImage) { await _employeeImageService.UpdateAsync(employeeImage); } else { await _employeeImageService.AddAsync(employeeImage); } } }
public ActionResult Edit([Bind(Include = "Id,ImageName,ImageByte,ImagePath")] EmployeeImageViewModel employeeImageViewModel) { if (ModelState.IsValid) { EmployeeImage employeeImage = Mapper.Map <EmployeeImage>(employeeImageViewModel); _employeeImageManager.Update(employeeImage); return(RedirectToAction("Index")); } return(View(employeeImageViewModel)); }
public async Task <IActionResult> EditEmployeeImage(EmployeeImageViewModel viewModel) { if (ModelState.IsValid) { await _profileViewModelService.UpdateEmployeeImage(viewModel); return(RedirectToAction(nameof(Index), new { employeeId = viewModel.EmployeeId })); } return(View(viewModel)); }
public async Task <EmployeeImageViewModel> GetEmployeeImage(string employeeId) { var viewModel = new EmployeeImageViewModel(); var image = await _employeeImageService.GetByEmployeeId(employeeId); if (image != null) { viewModel.ImageId = image.ImageId; } viewModel.EmployeeId = employeeId; viewModel.ProfileHeader = await GetProfileHeader(employeeId); return(viewModel); }
// GET: EmployeeImages/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EmployeeImage employeeImage = _employeeImageManager.FindById((int)id); if (employeeImage == null) { return(HttpNotFound()); } EmployeeImageViewModel employeeImageViewModel = Mapper.Map <EmployeeImageViewModel>(employeeImage); return(View(employeeImageViewModel)); }
public JsonResult UploadImage(EmployeeImageViewModel employeeImageViewModel) { var file = employeeImageViewModel.ImageFile; byte[] imageBytes = null; int imgId = 0; if (file != null) { //file.SaveAs(Server.MapPath("/EmployeeProfileImages/" + file.FileName)); BinaryReader reader = new BinaryReader(file.InputStream); imageBytes = reader.ReadBytes(file.ContentLength); EmployeeImage employeeImage = new EmployeeImage(); employeeImage.ImageByte = imageBytes; employeeImage.ImageName = file.FileName; employeeImage.ImagePath = null; /*"/EmployeeProfileImages/" + file.FileName;*/ _employeeImageManager.Add(employeeImage); imgId = employeeImage.Id; } return(Json(imgId, JsonRequestBehavior.AllowGet)); }
public MainPage() { this.InitializeComponent(); this.ViewModel = new EmployeeViewModel(); this.ImageViewModel = new EmployeeImageViewModel(); }