Exemple #1
0
 public bool CreatePositionAssignment(PositionAssignmentCreate model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity =
             new PositionAssignment()
         {
             OwnerId    = _userId,
             PositionId =
                 ctx
                 .Positions
                 .FirstOrDefault(e => e.OwnerId == _userId).PositionId,
             WorkerId =
                 ctx
                 .Workers
                 .FirstOrDefault(e => e.OwnerId == _userId).WorkerId,
             Notes   = model.Notes,
             ShiftId =
                 ctx
                 .Shifts
                 .FirstOrDefault(e => e.OwnerId == _userId).ShiftId
         };
         ctx.PositionAssignments.Add(entity);
         return(ctx.SaveChanges() == 1);
     }
 }
Exemple #2
0
        public ActionResult Create(PositionAssignmentCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreatePositionAssignmentService();

            if (service.CreatePositionAssignment(model))
            {
                TempData["SaveResult"] = "This Position Assignment has been successfully created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Unfortunately this Position Assignment was unable to be created at this time.");

            return(View(model));
        }