// GET: Promotions/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Promotion promotion = db.Promotions.Find(id);

            if (promotion == null)
            {
                return(HttpNotFound());
            }
            PromotionVM detail = new PromotionVM()
            {
                Cost               = promotion.Cost,
                PromotionDate      = promotion.PromotionDate,
                Description        = promotion.Description,
                Duration           = promotion.Duration,
                Id                 = promotion.Id,
                PromotionType      = promotion.PromotionType,
                Venue              = promotion.Venue,
                PromotionCreatorId = promotion.PromotionCreatorId
            };
            //attendees:
            var promotionAttendees = db.PromotionAttendees.Where(x => x.PromotionId == promotion.Id).ToList();

            if (promotionAttendees.Count > 0)
            {
                int[] ids = promotionAttendees.Select(x => x.AttendeeId).ToArray();
                detail.Attendees = db.Attendees.Where(x => ids.Contains(x.Id)).ToList();
            }
            return(View(detail));
        }
        public ActionResult Edit(
            PromotionVM promotion)
        {
            if (ModelState.IsValid)
            {
                Promotion        model   = db.Promotions.Find(promotion.Id);
                PromotionCreator creator = db.PromotionCreators.Find(promotion.PromotionCreatorId);
                //promotion:
                model.Cost          = promotion.Cost;
                model.Description   = promotion.Description;
                model.Duration      = promotion.Duration.Value;
                model.PromotionDate = promotion.PromotionDate.Value;
                model.PromotionType = promotion.PromotionType;
                model.Venue         = promotion.Venue;

                //creator:
                creator.FirstName   = promotion.FirstName;
                creator.Email       = promotion.Email;
                creator.LastName    = promotion.LastName;
                creator.PhoneNumber = promotion.PhoneNumber;

                db.Entry(model).State   = EntityState.Modified;
                db.Entry(creator).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Costs          = costs;
            ViewBag.PromotionTypes = promotionTypes;
            return(View(promotion));
        }
        // GET: Promotions/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Promotion promotion = db.Promotions.Find(id);

            if (promotion == null)
            {
                return(HttpNotFound());
            }
            PromotionCreator creator = db.PromotionCreators.Find(promotion.PromotionCreatorId);
            PromotionVM      prom    = new PromotionVM()
            {
                Cost               = promotion.Cost,
                Description        = promotion.Description,
                Duration           = promotion.Duration,
                Id                 = promotion.Id,
                PromotionCreatorId = promotion.PromotionCreatorId,
                PromotionDate      = promotion.PromotionDate,
                PromotionType      = promotion.PromotionType,
                Venue              = promotion.Venue,
                Email              = creator.Email,
                FirstName          = creator.FirstName,
                LastName           = creator.LastName,
                PhoneNumber        = creator.LastName
            };

            ViewBag.Costs          = costs;
            ViewBag.PromotionTypes = promotionTypes;
            return(View(prom));
        }
        public ActionResult Create(
            PromotionVM promotion)
        {
            if (ModelState.IsValid)
            {
                //promotion creator:
                PromotionCreator creator = new PromotionCreator()
                {
                    Email       = promotion.Email,
                    FirstName   = promotion.FirstName,
                    LastName    = promotion.LastName,
                    PhoneNumber = promotion.PhoneNumber
                };
                db.PromotionCreators.Add(creator);
                db.SaveChanges();

                Promotion model = new Promotion()
                {
                    Cost               = promotion.Cost,
                    Description        = promotion.Description,
                    Duration           = promotion.Duration.Value,
                    PromotionDate      = promotion.PromotionDate.Value,
                    PromotionType      = promotion.PromotionType,
                    Venue              = promotion.Venue,
                    PromotionCreatorId = creator.Id
                };
                db.Promotions.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Costs          = costs;
            ViewBag.PromotionTypes = promotionTypes;
            return(View(promotion));
        }
示例#5
0
        public ActionResult promote(int id)
        {
            PromotionVM model = new PromotionVM
            {
                jobDegrees = db.JobDegrees.ToList(),
                jobGroups  = db.jobGroups.ToList()
            };

            return(View(model));
        }
示例#6
0
        public ActionResult details(int id)
        {
            EditVM model = new EditVM
            {
                employe       = db.Employes.Include("permenentUser").SingleOrDefault(e => e.id == id),
                maritalStates = db.MaritalStates.ToList(),
            };

            PromotionVM promotionModel = new PromotionVM
            {
                jobDegrees    = db.JobDegrees.ToList(),
                jobGroups     = db.jobGroups.ToList(),
                permenentUser = model.employe.permenentUser
            };

            model.promotionVM = promotionModel;
            return(View(model));
        }
示例#7
0
 public ActionResult promoteUser(PromotionVM model, int employeId)
 {
     //if the model is valid
     if (ModelState.IsValid)
     {
         //update the user to make him permenent
         Employe emp = db.Employes.Include("permenentUser").SingleOrDefault(e => e.id == employeId);
         emp.permenentUser = model.permenentUser;
         db.Employes.AddOrUpdate(emp);
         db.SaveChanges();
         return(RedirectToAction("details", "Employe", new { id = employeId }));
     }
     else
     {
         model.jobDegrees = db.JobDegrees.ToList();
         model.jobGroups  = db.jobGroups.ToList();
         return(View("promote", model));
     }
 }