示例#1
0
        public ActionResult Edit(int id, TechEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.TechId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateTechService();

            if (service.UpdateTech(model))
            {
                TempData["SaveResult"] = $"{model.FirstName} {model.LastName} Was Updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", $"{model.FirstName} {model.LastName} Could Not Be Updated.");

            var skillList = new SelectList(service.SkillList(), "SkillId", "SkillName", model.SkillId);

            ViewBag.SkillId = skillList;
            var locationList = new SelectList(service.LocationList(), "LocationId", "FullLocation", model.LocationId);

            ViewBag.LocationId = locationList;

            return(View(model));
        }
示例#2
0
        public ActionResult Edit(int id)
        {
            var service   = CreateTechService();
            var skillList = new SelectList(service.SkillList(), "SkillId", "SkillName");

            ViewBag.SkillId = skillList;
            var locationList = new SelectList(service.LocationList(), "LocationId", "FullLocation");

            ViewBag.LocationId = locationList;

            var detail = service.GetTechById(id);
            var model  =
                new TechEdit
            {
                TechId    = detail.TechId,
                FirstName = detail.FirstName,
                LastName  = detail.LastName,


                LocationId = detail.LocationId,

                SkillId = detail.SkillId,

                HourlyRate           = detail.HourlyRate,
                WeekendRate          = detail.WeekendRate,
                AfterHoursRate       = detail.AfterHoursRate,
                HolidayRate          = detail.HolidayRate,
                EmergencySameDayRate = detail.EmergencySameDayRate,
                EmergencyNextDayRate = detail.EmergencyNextDayRate
            };

            return(View(model));
        }
示例#3
0
        public bool UpdateTech(TechEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Technicians
                    .Single(e => e.TechId == model.TechId && e.OwnerId == _userId);

                entity.TechId    = model.TechId;
                entity.FirstName = model.FirstName;
                entity.LastName  = model.LastName;


                entity.LocationId = model.LocationId;

                entity.SkillId = model.SkillId;

                entity.HourlyRate           = model.HourlyRate;
                entity.WeekendRate          = model.WeekendRate;
                entity.AfterHoursRate       = model.AfterHoursRate;
                entity.HolidayRate          = model.HolidayRate;
                entity.EmergencySameDayRate = model.EmergencySameDayRate;
                entity.EmergencyNextDayRate = model.EmergencyNextDayRate;

                entity.ModifiedUtc = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }