private IResult CheckDoctorExist(int doctorImageId) { DoctorImage selectedDoctorImage = _doctorImageDal.Get(d => d.doctorId == doctorImageId); if (selectedDoctorImage != null) { return(new ErrorResult(Messages <DoctorImage> .NullType)); } return(new SuccessResult()); }
public IActionResult Update([FromForm(Name = "Image")] IFormFile file, [FromForm] DoctorImage doctorImage) { var result = _doctorImageService.Update(doctorImage, file); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
private IResult CheckIfLimitExceeded(DoctorImage doctorImage) { var doctorImageSize = _doctorImageDal.GetAll().Count; if (doctorImageSize > 5) { return(new ErrorResult(Messages <DoctorImage> .LimitExceeded)); } return(new SuccessResult()); }
private void CheckImageFile(DoctorImage doctorImage, IFormFile file) { if (file == null) { doctorImage.imagePath = DefaultDoctorImagePath; } var result = _fileHelper.Upload(file); doctorImage.imagePath = result.Message; }
public IActionResult Delete([FromForm] int id) { DoctorImage deletedEntity = _doctorImageService.GetById(id).Data; var result = _doctorImageService.Delete(deletedEntity); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IResult Delete(DoctorImage doctorImage) { var result = BusinessRules.Run(CheckDoctorExist(doctorImage.doctorId)); if (!result.Success) { return(new ErrorResult(result.Message)); } _doctorImageDal.Delete(doctorImage); _fileHelper.Delete(doctorImage.imagePath); return(new SuccessResult(Messages <DoctorImage> .Deleted)); }
public IResult Update(DoctorImage doctorImage, IFormFile file) { IResult result = BusinessRules.Run(CheckIfLimitExceeded(doctorImage), CheckFileTypeValid(Path.GetExtension(file.FileName))); if (!result.Success) { return(new ErrorResult(result.Message)); } ImageUpdate(doctorImage, file); _doctorImageDal.Update(doctorImage); return(new SuccessResult(Messages <DoctorImage> .Updated)); }
public IResult Add(DoctorImage doctorImage, IFormFile file) { IResult result = BusinessRules.Run(CheckIfLimitExceeded(doctorImage), CheckDoctorExist(doctorImage.doctorId), CheckFileTypeValid(Path.GetExtension(file.FileName))); if (result != null) { return(new ErrorResult(result.Message)); } CheckImageFile(doctorImage, file); _doctorImageDal.Add(doctorImage); return(new SuccessResult(Messages <DoctorImage> .Added)); }
private void ImageUpdate(DoctorImage doctorImage, IFormFile file) { var result = _doctorImageDal.Get(d => d.imageId == doctorImage.imageId).imagePath; if (doctorImage.imagePath == DefaultDoctorImagePath && file != null) { var uploadedImage = _fileHelper.Upload(file); doctorImage.imagePath = uploadedImage.Message; } else if (result == DefaultDoctorImagePath && file == null) { doctorImage.imagePath = DefaultDoctorImagePath; } else if (file == null && result != DefaultDoctorImagePath) { _fileHelper.Delete(result); doctorImage.imagePath = DefaultDoctorImagePath; } else { var updatedImage = _fileHelper.Update(file, doctorImage.imagePath); doctorImage.imagePath = updatedImage.Message; } }
public ActionResult Create(DoctorAndWorkHours model, IFormFile Image) { var doctor = new Doctor() { Name = model.Name, Surname = model.Surname, Scope = model.Scope, Address = model.Address, Office = model.Office, PhoneNumber = model.PhoneNumber, }; _context.Doctors.Add(doctor); _context.SaveChanges(); var lastDoctorId = doctor.Id; if (Image != null) { if (Image.Length > 0) //Convert Image to byte and save to database { byte[] p1 = null; using (var fs1 = Image.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } var doctorImage = new DoctorImage() { Id = lastDoctorId, Image = p1 }; _context.DoctorImages.Add(doctorImage); _context.SaveChanges(); } } else { byte[] photo = System.IO.File.ReadAllBytes("wwwroot/images/blank.png"); var doctorImage = new DoctorImage() { Id = lastDoctorId, Image = photo }; _context.DoctorImages.Add(doctorImage); _context.SaveChanges(); } var workHours = new DoctorWorkHours() { Id = lastDoctorId, MondayFrom = model.MondayFrom, MondayTo = model.MondayTo, TuesdayFrom = model.TuesdayFrom, TuesdayTo = model.TuesdayTo, WednesdayFrom = model.WednesdayFrom, WednesdayTo = model.WednesdayTo, ThursdayFrom = model.ThursdayFrom, ThursdayTo = model.ThursdayTo, FridayFrom = model.FridayFrom, FridayTo = model.FridayTo, SaturdayFrom = model.SaturdayFrom, SaturdayTo = model.SaturdayTo, SundayFrom = model.SundayFrom, SundayTo = model.SundayTo }; _context.DoctorWorkHours.Add(workHours); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }