public void GetNewDelegationIdTest()
        {
            // Act
            var result = IdService.GetNewDelegationId(context);

            // Assert
            Assert.IsNotNull(result);
        }
        public ActionResult SaveOptions(DepartmentViewModel model)
        {
            departmentService      = new DepartmentService(context);
            collectionPointService = new CollectionPointService(context);
            userService            = new UserService(context);
            statusService          = new StatusService(context);
            delegationService      = new DelegationService(context);

            int        status     = 0;
            Department dpt        = departmentService.FindDepartmentByUser(userService.FindUserByEmail(CurrentUserName));
            Delegation delegation = new Delegation();

            dpt.UpdatedDateTime = DateTime.Now;
            dpt.UpdatedBy       = userService.FindUserByEmail(System.Web.HttpContext.Current.User.Identity.GetUserName());
            dpt.Representative  = userService.FindUserByEmail(model.DepartmentRep);
            dpt.CollectionPoint = collectionPointService.FindCollectionPointById(Convert.ToInt32(model.CollectionPoint));

            if (departmentService.Save(dpt) != null)
            {
                // Send notifications to all Store Clerks
                foreach (var user in new UserService(context).FindUsersByDepartment(departmentService.FindDepartmentByDepartmentCode("STOR")).Where(r => r.Roles.Select(ur => ur.RoleId).Contains("3")))
                {
                    var notification = new NotificationService(context).CreateChangeCollectionPointNotification(dpt, user);
                    new NotificationApiController()
                    {
                        context = context
                    }.SendNotification(notification.NotificationId.ToString());
                    new NotificationApiController()
                    {
                        context = context
                    }.SendEmail(notification.NotificationId.ToString());
                }
                status = 1;
            }

            delegation.Receipient = userService.FindUserByEmail(model.DelegationRecipient);

            if (delegation.Receipient != null && model.StartDate != null && model.EndDate != null)
            {
                delegation.DelegationId    = IdService.GetNewDelegationId(context);
                delegation.StartDate       = DateTime.Parse(model.StartDate, new CultureInfo("fr-FR", false));
                delegation.EndDate         = DateTime.Parse(model.EndDate, new CultureInfo("fr-FR", false));
                delegation.CreatedDateTime = DateTime.Now;
                //delegation.CreatedBy = user;
                delegation.CreatedBy = userService.FindUserByEmail(CurrentUserName);
                delegation.Status    = statusService.FindStatusByStatusId(1);
                delegationService.DelegateManager(delegation);
                status = 2;

                // Role
                //userService.AddDepartmentHeadRole(delegation.Receipient.Email);
            }

            if (delegation.Receipient != null && model.StartDate == null && model.EndDate == null)
            {
                status = 3;
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }