Exemplo n.º 1
0
 //--------------------   Animal Vaccine  -------------------------------------
 #region
 public static bool AddAnimalVaccine(AnimalVaccineAdd newentry, string operatorname)
 {
     try
     {
         using (AnimalInformationContext datamodel = new AnimalInformationContext())
         {
             var animal = AnimalInformationDBAcces.GetAnimalInfoByID(newentry.AnimalId);
             if (animal != null)
             {
                 Vaccination add = new Vaccination();
                 add.AnimalId          = newentry.AnimalId;
                 add.VaccinationDate   = newentry.VaccinationDate;
                 add.VaccineName       = newentry.VaccineName;
                 add.NextVaccationDate = newentry.NextVaccationDate;
                 add.Comments          = newentry.Comments;
                 add.IsApplied         = true;
                 add.OperatorName      = operatorname;
                 datamodel.Vaccinations.Add(add);
                 datamodel.SaveChanges();
                 return(true);
             }
             return(false);
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemplo n.º 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);
            }
        }