private bool IsValid(DonationAppointment Entity)
 {
     if (Entity.AppointmentDate < DateTime.Today)
     {
         return(false);
     }
     return(true);
 }
        public DonationAppointment Update(int id, DateTime AppointmentDate, int?RequestId, bool confirmed, int ProfileId, int TransfusionId)
        {
            DonationAppointment p = new DonationAppointment()
            {
                Id                  = id,
                RequestId           = RequestId,
                AppointmentDate     = AppointmentDate,
                Confirmed           = confirmed,
                ProfileId           = ProfileId,
                TransfusionCenterId = TransfusionId
            };

            Repository.Update(p);

            return(p);
        }
        public DonationAppointment Add(DateTime AppointmentDate, int?RequestId, bool confirmed, string UserId, int TransfusionId)
        {
            int ProfileId = profileService.GetProfileId(UserId);

            DonationAppointment p = new DonationAppointment()
            {
                RequestId           = RequestId,
                AppointmentDate     = AppointmentDate,
                Confirmed           = confirmed,
                ProfileId           = ProfileId,
                TransfusionCenterId = TransfusionId
            };

            Repository.Add(p);

            return(p);
        }
 public void Update(DonationAppointment Entity)
 {
     if (IsValid(Entity))
     {
         using (var context = new DatabaseContainer())
         {
             context.DonationAppointmentSet.AddOrUpdate(Entity);
             try
             {
                 context.SaveChanges();
             }
             catch (Exception)
             {
                 throw new ArgumentException("An exception occured");
             }
         }
     }
 }
 public void Add(DonationAppointment Entity)
 {
     if (IsValid(Entity))
     {
         using (var context = new DatabaseContainer())
         {
             context.DonationAppointmentSet.Add(Entity);
             try
             {
                 context.SaveChanges();
             }
             catch (Exception)
             {
                 throw new ArgumentException("There is already a donation appointment with that id");
             }
         }
     }
 }
        public ActionResult DonationComplete(AddDonateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("AddDonation", model));
            }

            if (model.Plasma < 0 || model.RedCell < 0 || model.Thrombocytes < 0)
            {
                ModelState.AddModelError(String.Empty, "Quantity cannot be 0");
                return(View("AddDonation", model));
            }
            else if (model.Date < DateTime.Today)
            {
                ModelState.AddModelError(String.Empty, "Date cannot be before today");
                return(View("AddDonation", model));
            }
            else
            {
                DonationAppointment app = _donationAppointmentService.GetById(model.AppointmentId);
                _donationAppointmentService.Update(app.Id, app.AppointmentDate, app.RequestId, true, app.ProfileId,
                                                   app.TransfusionCenterId);
                Plasma       p = _plasmaService.Add(model.Date.AddMonths(2), null, model.Plasma);
                RedCell      r = _redCellService.Add(model.Date.AddDays(42), null, model.RedCell);
                Thrombocytes t = _thrombocytesService.Add(model.Date.AddDays(5), null, model.Thrombocytes);

                BloodSeparation b = _bloodSeparation.Add(p.Id, r.Id, t.Id);

                Donation d = _donationService.Add(app.RequestId, model.Plasma + model.RedCell + model.Thrombocytes, model.Date, false,
                                                  StatusEnum.Preparated, app.ProfileId, b.Id, model.BloodType);

                LabResult lb = _labResultService.Add(false, false, false, false, false, "None", d.Id);
            }


            return(View("AddDonation", model));
        }