Esempio n. 1
0
        public ActionResult Create(TechCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateTechService();

            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;


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

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



            return(View(model));
        }
Esempio n. 2
0
        public bool CreateTech(TechCreate model)
        {
            var entity =
                new Technician()
            {
                OwnerId   = _userId,
                FirstName = model.FirstName,
                LastName  = model.LastName,

                LocationId = model.LocationId,

                SkillId = model.SkillId,

                HourlyRate           = model.HourlyRate,
                WeekendRate          = model.WeekendRate,
                AfterHoursRate       = model.AfterHoursRate,
                HolidayRate          = model.HolidayRate,
                EmergencySameDayRate = model.EmergencySameDayRate,
                EmergencyNextDayRate = model.EmergencyNextDayRate,
                CreatedUtc           = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Technicians.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }