示例#1
0
 public static bool AddVaccination(AnimalVaccinationInfoAdd newentry, string operatorname)
 {
     try
     {
         using (AnimalInformationContext datamodel = new AnimalInformationContext())
         {
             foreach (var item in newentry.VaccinationInfo)
             {
                 Vaccination add = new Vaccination();
                 add.AnimalId          = item.AnimalId;
                 add.VaccinationDate   = newentry.VaccinationDate;
                 add.VaccineName       = newentry.VaccineName;
                 add.NextVaccationDate = newentry.NextVaccationDate;
                 add.Comments          = item.Comments;
                 add.IsApplied         = item.isNotApplied ? false : true;
                 add.OperatorName      = operatorname;
                 datamodel.Vaccinations.Add(add);
                 datamodel.SaveChanges();
             }
             if (newentry.GetNotiFication)
             {
                 List <Notification> NotificationInfo = new List <Notification>();
                 var typeinf = datamodel.AnimalTypes.Where(a => a.PKAnimalTypeId == newentry.AnimalTypeId).FirstOrDefault();
                 for (int i = -3; i < 1; i++)
                 {
                     NotificationInfo.Add(new Notification
                     {
                         Date = newentry.NextVaccationDate.Date.AddDays(i),
                         NotificationMessage = "Animal type: " + typeinf.AnimalTypeName + ", next Vaccination Date of: " + newentry.VaccineName + " is " + newentry.NextVaccationDate.ToString("dddd, dd MMMM yyyy"),
                         GroupID             = "Vaccine" + newentry.VaccineName + newentry.VaccinationDate.ToString("MM/dd/yyyy")
                     });
                 }
                 AgroExpressDBAccess.AddNotificationList(NotificationInfo);
             }
             return(true);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
示例#2
0
        //--------------------   Animal Medication  -------------------------------------
        #region
        public static bool AddAnimalMedication(AnimalMdicationAdd newentry, string operatorname)
        {
            try
            {
                using (AnimalInformationContext datamodel = new AnimalInformationContext())
                {
                    var animal = AnimalInformationDBAcces.GetAnimalInfoByID((int)newentry.AnimalId);
                    if (animal != null)
                    {
                        Medication add = new Medication();
                        add.AnimalId       = (int)newentry.AnimalId;
                        add.MedicationDate = newentry.MedicationDate;
                        add.MedicineName   = newentry.MedicineName;
                        add.Comments       = newentry.Comments;


                        add.OperatorName = operatorname;

                        datamodel.Medication.Add(add);
                        datamodel.SaveChanges();



                        var medicineid = datamodel.Medication.SingleOrDefault(a => a.MedicationDate == newentry.MedicationDate && a.MedicineName == newentry.MedicineName && a.AnimalId == newentry.AnimalId);

                        bool isinserted = false;

                        if (medicineid.PKMedicationId != 0)
                        {
                            var      animalInfo      = datamodel.AnimalInformations.Where(a => a.PKAnimalId == newentry.AnimalId).FirstOrDefault();
                            var      medicationdates = newentry.SelectedCourseDates;
                            Char     delimiter       = ',';
                            string[] split           = medicationdates.Split(delimiter);

                            string dates;
                            List <Notification> NotificationInfo = new List <Notification>();


                            for (var i = 0; i < split.Length; i++)
                            {
                                MedicineCourse addnew = new MedicineCourse();
                                addnew.medicationId = medicineid.PKMedicationId;
                                addnew.Dose         = newentry.Dose;
                                addnew.status       = true;

                                dates = split[i];

                                var      sourcedater = DateTime.Parse(dates);
                                var      date        = sourcedater.ToString("M/d/yyyy");
                                DateTime outputdater;
                                DateTime.TryParseExact(date.ToString(), "M/d/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out outputdater);

                                addnew.MedicationDate = outputdater;
                                if (AnimalInformationDBAcces.AddMedicationDose(addnew))
                                {
                                    if (newentry.GetNotiFication)
                                    {
                                        var typeinf = datamodel.AnimalTypes.Where(a => a.PKAnimalTypeId == newentry.AnimalTypeId).FirstOrDefault();
                                        for (int index = -1; index < 1; index++)
                                        {
                                            NotificationInfo.Add(new Notification
                                            {
                                                Date = addnew.MedicationDate.Date.AddDays(index),
                                                NotificationMessage = "Animal code name: " + animalInfo.AnimalCodeName + ", Medicine Name: " + newentry.MedicineName + ", Date: " + addnew.MedicationDate.ToString("dddd, dd MMMM yyyy"),
                                                GroupID             = "Medicine" + newentry.MedicineName + newentry.MedicationDate.ToString("MM/dd/yyyy")
                                            });
                                        }
                                    }
                                    isinserted = true;
                                }
                            }
                            if (newentry.GetNotiFication)
                            {
                                AgroExpressDBAccess.AddNotificationList(NotificationInfo);
                            }
                        }
                        if (isinserted == true)
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }