예제 #1
0
        // GET: Trainors/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                logger.Warn("Received null Trainer Id to delete");

                return(Content("{\"Type\":\"Warn\", \"Message\":\"Received null Trainer Id to delete\"}"));
            }
            else
            {
                Trainor trainer = db.Trainors.Find(id);

                if (trainer == null)
                {
                    logger.WarnFormat("Trainer not found to delete, Id: {0}", id);
                    return(Content("{\"Type\":\"Warn\", \"Message\":\"Trainer not found to delete with the Id:" + id + "\"}"));
                }
                else
                {
                    List <TrainorAllocationForEventSeg> allocations = db.TrainorEventSegAllocations.Where(e => e.Trainor.Id == id).ToList();
                    if (allocations.Count() > 0)
                    {
                        return(Content("{\"Type\":\"Warn\", \"Message\":\"The trainer is associated with one or more Event Segment Allocation. Please delete the related Trainer Allocations first\"}"));
                    }
                    else
                    {
                        return(Content("{\"Type\":\"Confirm\", \"Message\":\"Are you sure you want to delete the Trainer: " + trainer.FirstName + " " + trainer.Lastname + "\", \"Id\": \" " + trainer.Id + "\"}"));
                    }
                }
            }
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "EquipmentName, EquipmentAllocations")] Equipment equipment)
        {
            List <EquipmentAllocation> allocations = new List <EquipmentAllocation>();

            if (equipment.EquipmentAllocations != null)
            {
                allocations.AddRange(equipment.EquipmentAllocations);
                equipment.EquipmentAllocations.Clear();
            }

            db.Equipment.Add(equipment);

            foreach (EquipmentAllocation allocation in allocations)
            {
                Trainor trainer = db.Trainors.Find(allocation.Trainor.Id);
                if (trainer != null)
                {
                    allocation.Trainor = trainer;
                }
                equipment.EquipmentAllocations.Add(allocation);
            }

            db.SaveChanges();
            logger.InfoFormat("Equipment Created, Name : {0}, Id: {1}", equipment.EquipmentName, equipment.Id);
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public async Task <ActionResult> SendMail(int id, string subject, string messageBody, string idName)
        {
            string email;
            string name;

            if ("trainerId".Equals(idName))
            {
                Trainor trainer = db.Trainors.Find(id);
                if (trainer != null && trainer.Email != null)
                {
                    email = trainer.Email;
                    name  = trainer.FirstName + " " + trainer.Lastname;
                }
                else
                {
                    var errorMessage = (trainer == null ? "Specified trainer was not found" : "Specified trainer doesn't have an email address assigned");
                    return(Content("{\"Type\":\"Warn\", \"Message\":\"" + errorMessage + "\"}"));
                }
            }
            else
            {
                ClientContact clientContact = db.ClientContacts.Find(id);
                if (clientContact != null && clientContact.ContactEmail != null)
                {
                    email = clientContact.ContactEmail;
                    name  = clientContact.ContactName;
                }
                else
                {
                    var errorMessage = (clientContact == null ? "Specified client contact was not found" : "Specified client contact doesn't have an email address assigned");
                    return(Content("{\"Type\":\"Warn\", \"Message\":\"" + errorMessage + "\"}"));
                }
            }
            string modifiedMessage = messageBody.Replace("\n", "<br/>").Replace(Environment.NewLine, "<br/>");
            //System.Web.HttpUtility.HtmlEncode(messageBody);
            var body    = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
            var message = new MailMessage();

            message.To.Add(new MailAddress(email));
            message.To.Add(new MailAddress("*****@*****.**"));
            message.Subject    = subject;
            message.Body       = string.Format(body, senderName, senderEmailAddress, modifiedMessage);
            message.IsBodyHtml = true;
            using (var smtp = new SmtpClient())
            {
                try
                {
                    await smtp.SendMailAsync(message);

                    var successMessage = "Email Successfully sent to " + name;
                    logger.InfoFormat("Email Successfully sent to {0}", name);
                    return(Content("{\"Type\":\"Success\", \"Message\":\"" + successMessage + "\"}"));
                }
                catch (Exception e)
                {
                    return(Content("{\"Type\":\"Success\", \"Message\":\"" + e.Message + "\"}"));
                }
            }
        }
예제 #4
0
        public JsonResult DeleteConfirmed(int id)
        {
            Trainor trainor = db.Trainors.Include(q => q.Qualifications).Include(a => a.Address).Where(t => t.Id == id).First();

            db.Qualifications.RemoveRange(trainor.Qualifications);
            db.Addresses.Remove(trainor.Address);
            db.Trainors.Remove(trainor);
            db.SaveChanges();
            logger.InfoFormat("Trainer deleted, Name: {0}, Id: {1}", trainor.FirstName, trainor.Id);
            return(Json("Successfully deleted the trainer: " + trainor.FirstName + " " + trainor.Lastname));
        }
예제 #5
0
        public ActionResult Create([Bind(Include = "Id,FirstName,Lastname,PhoneNumber,Email,DOB,TaxFileNo,Address,Qualifications")] Trainor trainor)
        {
            if (ModelState.IsValid)
            {
                db.Trainors.Add(trainor);
                db.SaveChanges();
                logger.InfoFormat("Trainer Created, Name : {0}, Id: {1}", trainor.FirstName, trainor.Id);
                return(RedirectToAction("Index"));
            }

            return(View(trainor));
        }
예제 #6
0
        // GET: Trainors/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                logger.Warn("Received null Trainer Id to modify");
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Trainor trainor = db.Trainors.Include(x => x.Qualifications).Include(y => y.Address).Where(z => z.Id == id).First();

            if (trainor == null)
            {
                logger.WarnFormat("Trainer not found to modify, Id: {0}", id);
                return(HttpNotFound());
            }
            return(View(trainor));
        }
예제 #7
0
 public ActionResult Create(TrainorAllocationForEventSeg trainorAllocation, int eventSegmentId, int trainerId)
 {
     if (ModelState.ContainsKey("trainorAllocation.EventSegment"))
     {
         ModelState["trainorAllocation.EventSegment"].Errors.Clear();
     }
     if (ModelState.IsValid)
     {
         EventSegment evntSegment = db.EventSegments.Include(c => c.TrainorAllocations).Where(i => i.Id == eventSegmentId).First();
         Trainor      trainer     = db.Trainors.Find(trainerId);
         trainorAllocation.Trainor = trainer;
         evntSegment.TrainorAllocations.Add(trainorAllocation);
         db.SaveChanges();
         logger.InfoFormat("Trainer Allocation created for the EventSegment : {0}, with the Trainer : {1}", evntSegment.Name, trainer.FirstName + " " + trainer.Lastname);
         return(Json("Trainer Allocation created for Trainer: " + trainer.FirstName + " " + trainer.Lastname));
     }
     return(Json("Invalid Model State"));
 }
예제 #8
0
        public ActionResult Edit([Bind(Include = "Id,FirstName,Lastname,PhoneNumber,Email,DOB,TaxFileNo,Address,Qualifications")] Trainor trainer)
        {
            if (ModelState.IsValid)
            {
                logger.DebugFormat("Modifying trainer of the Name: {0} and Id:{}", trainer.FirstName, trainer.Id);
                Trainor dbTrainer = db.Trainors.Include(c => c.Qualifications).Include(a => a.Address).Where(i => i.Id == trainer.Id).First();

                //updating the simple trainer fields
                dbTrainer.FirstName   = trainer.FirstName;
                dbTrainer.Lastname    = trainer.Lastname;
                dbTrainer.PhoneNumber = trainer.PhoneNumber;
                dbTrainer.TaxFileNo   = trainer.TaxFileNo;
                dbTrainer.Email       = trainer.Email;
                dbTrainer.DOB         = trainer.DOB;


                if (trainer.Address != null)
                {
                    var dbAddress = db.Addresses.Find(trainer.Address.Id);
                    if (dbAddress != null)
                    {
                        db.Entry(dbAddress).CurrentValues.SetValues(trainer.Address);
                        db.Entry(dbAddress).State = EntityState.Modified;
                    }
                    else
                    {
                        dbTrainer.Address = trainer.Address;
                    }
                }
                else if (dbTrainer.Address != null)
                {
                    db.Entry(trainer.Address).State = EntityState.Deleted;
                }

                //Deleting the deleted qualifications
                if (dbTrainer.Qualifications != null)
                {
                    List <Qualification> qualificationsToBeDeleted = new List <Qualification>();
                    if (trainer.Qualifications != null)
                    {
                        qualificationsToBeDeleted = (from qualification in dbTrainer.Qualifications
                                                     let item = trainer.Qualifications.SingleOrDefault(i => i.Id == qualification.Id)
                                                                where item == null
                                                                select qualification).ToList();
                    }
                    else
                    {
                        qualificationsToBeDeleted = dbTrainer.Qualifications.ToList();
                    }

                    if (qualificationsToBeDeleted.Any())
                    {
                        foreach (var clientContact in qualificationsToBeDeleted.ToList())
                        {
                            db.Entry(clientContact).State = EntityState.Deleted;
                        }
                    }
                }

                if (trainer.Qualifications != null)
                {
                    foreach (var qualification in trainer.Qualifications)
                    {
                        //Updating the existing qualifications
                        if (qualification.Id > 0)
                        {
                            var qualificationDB = db.Qualifications.Single(e => e.Id == qualification.Id);
                            db.Entry(qualificationDB).CurrentValues.SetValues(qualification);
                            db.Entry(qualificationDB).State = EntityState.Modified;
                        }
                        //Adding new qualification
                        else
                        {
                            dbTrainer.Qualifications.Add(qualification);
                        }
                    }
                }
                db.SaveChanges();
                logger.InfoFormat("Trainer modified, Name: {0}, Id: {1}", dbTrainer.FirstName, trainer.Id);
                return(RedirectToAction("Index"));
            }
            return(View(trainer));
        }
예제 #9
0
        public ActionResult Edit([Bind(Include = "Id,EquipmentName,EquipmentAllocations")] Equipment equipment)
        {
            logger.DebugFormat("Modifying Equipment of the Name: {0} and Id:{1}", equipment.EquipmentName, equipment.Id);
            Equipment dbEquipment = db.Equipment.Include(c => c.EquipmentAllocations).Where(i => i.Id == equipment.Id).First();

            //updating the Equipment fields
            dbEquipment.EquipmentName = equipment.EquipmentName;

            //Deleting the deleted allocations
            if (dbEquipment.EquipmentAllocations != null)
            {
                List <EquipmentAllocation> allocationsToBeDeleted = new List <EquipmentAllocation>();
                if (equipment.EquipmentAllocations != null)
                {
                    allocationsToBeDeleted = (from equipmentAllocation in dbEquipment.EquipmentAllocations
                                              let item = equipment.EquipmentAllocations.SingleOrDefault(i => i.Id == equipmentAllocation.Id)
                                                         where item == null
                                                         select equipmentAllocation).ToList();
                }
                else
                {
                    allocationsToBeDeleted = dbEquipment.EquipmentAllocations.ToList();
                }

                if (allocationsToBeDeleted.Any())
                {
                    foreach (var clientContact in allocationsToBeDeleted.ToList())
                    {
                        db.Entry(clientContact).State = EntityState.Deleted;
                    }
                }
            }

            if (equipment.EquipmentAllocations != null)
            {
                foreach (var equipmentAllocation in equipment.EquipmentAllocations)
                {
                    Trainor trainer = db.Trainors.Find(equipmentAllocation.Trainor.Id);
                    if (trainer != null)
                    {
                        equipmentAllocation.Trainor = trainer;
                    }

                    //Updating the existing allocations
                    if (equipmentAllocation.Id > 0)
                    {
                        var equipmentAllocationDB = db.EquipmentAllocations.Single(e => e.Id == equipmentAllocation.Id);
                        db.Entry(equipmentAllocationDB).CurrentValues.SetValues(equipmentAllocation);
                        db.Entry(equipmentAllocationDB).State = EntityState.Modified;
                    }
                    //Adding new allocations
                    else
                    {
                        dbEquipment.EquipmentAllocations.Add(equipmentAllocation);
                    }
                }
            }
            db.SaveChanges();
            logger.InfoFormat("Equipment modified, Name: {0}, Id: {1}", dbEquipment.EquipmentName, equipment.Id);
            return(RedirectToAction("Index"));
        }