public void Update(DailyReportMedicationViewModel model) { this.Date = model.Date; this.Medication = model.Medication; this.OrganizationId = model.OrganizationId; this.PersonId = model.PersonId; this.Amount = model.Amount; this.Time = model.Time; this.Type = model.Type; }
public async Task <JsonResult> AddEditMedication(DailyReportMedicationViewModel model) { if (ModelState.IsValid) { if (model.Id == null) { var medication = DailyReportMedication.Create( model.PersonId, model.ClassId, model.OrganizationId, model.Date, model.Medication, model.Time, model.Amount, model.Type, _userId); await _unitOfWork.DailyReportMedications.Insert(medication); } else { var medication = await _unitOfWork.DailyReportMedications.GetOneAsync(x => x.IsActive && x.Id == model.Id); medication.Update(model); _unitOfWork.DailyReportMedications.Update(medication); } var result = await _unitOfWork.SaveAsync(); if (result.Succeeded) { return(Json(new JsonMessage { Color = "#ff6849", Message = "Medication saved", Header = "Success", Icon = "success", AdditionalData = model })); } return(Json(new JsonMessage { Color = "#ff6849", Message = "Save Error", Header = "Error", Icon = "error", AdditionalData = model })); } else { return(Json(new JsonMessage { Color = "#ff6849", Message = "Model Error", Header = "Error", Icon = "error", AdditionalData = model })); } }
public async Task <IActionResult> EditMedication(Guid id) { var medication = await _unitOfWork.DailyReportMedications.GetOneAsync(x => x.IsActive && x.Id == id); return(View("AddEditMedication", DailyReportMedicationViewModel.Create(medication))); }