public async Task <IActionResult> AddServiceGroup(ServiceGroupViewModel viewModel)
        {
            //clear error list
            errors.Clear();

            //Get CongregationID
            var userData = HttpContext.Session.GetObjectFromJson <LoginPassedDataViewModel>("userCredentials");
            //ServiceGroupListbyID
            var serviceGroupList = await _serviceGroups.GetServiceGroupsbyCongAsync(userData.CongregationId);

            //ViewModel Validation
            ServiceGroupValidator validator = new ServiceGroupValidator(serviceGroupList);
            var results = validator.Validate(viewModel);

            if (results.IsValid == true)
            {
                //Map model
                var serviceGroupListAdded = _mapper.Map <ServiceGroups>(viewModel);
                //Insert service group
                _serviceGroups.InsertAsync(serviceGroupListAdded);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View());
            }
        }
        public async Task <IActionResult> EditAsync(ServiceGroupViewModel viewModel)
        {
            //clear error list
            errors.Clear();

            //Get CongregationID
            var userData = HttpContext.Session.GetObjectFromJson <LoginPassedDataViewModel>("userCredentials");
            //ServiceGroupListbyID
            var serviceGroupList = await _serviceGroups.GetServiceGroupsbyCongAsync(userData.CongregationId);

            //ViewModel Validation
            ServiceGroupValidator validator = new ServiceGroupValidator(serviceGroupList);
            var results = validator.Validate(viewModel);

            if (results.IsValid == true)
            {
                //Use get congregation info from DB
                var serviceGroupUpdate = _mapper.Map <ServiceGroups>(viewModel);
                serviceGroupUpdate.FKCongregationId = userData.Id;
                //Use the created map
                _serviceGroups.UpdateAsync(serviceGroupUpdate);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                foreach (ValidationFailure failure in results.Errors)
                {
                    errors.Add($"{failure.PropertyName}:{failure.ErrorMessage}");
                }
                return(View(viewModel));
            }
        }
Exemple #3
0
        public static void UpdateServiceGroup(this ServiceGroup serviceGroup, ServiceGroupViewModel serviceGroupVM)
        {
            serviceGroup.ID                 = serviceGroupVM.ID;
            serviceGroup.Alias              = serviceGroupVM.Alias;
            serviceGroup.CreatedBy          = serviceGroupVM.CreatedBy;
            serviceGroup.CreatedDate        = serviceGroupVM.CreatedDate;
            serviceGroup.Description        = serviceGroupVM.Description;
            serviceGroup.DisplayOrder       = serviceGroupVM.DisplayOrder;
            serviceGroup.Image              = serviceGroupVM.Image;
            serviceGroup.MetaDescription    = serviceGroupVM.MetaDescription;
            serviceGroup.MetaKeyWord        = serviceGroupVM.MetaKeyWord;
            serviceGroup.Name               = serviceGroupVM.Name;
            serviceGroup.MainServiceGroupId = serviceGroupVM.MainServiceGroupId;

            serviceGroup.Status      = serviceGroupVM.Status;
            serviceGroup.UpdatedBy   = serviceGroupVM.UpdatedBy;
            serviceGroup.UpdatedDate = serviceGroupVM.UpdatedDate;
        }
Exemple #4
0
        internal static List <ServiceGroupViewModel> MappingServiceGroup(List <ServiceGroup> lstServiceGroup)
        {
            ServiceGroupViewModel        serviceVM    = new ServiceGroupViewModel();
            List <ServiceGroupViewModel> lstServiceVM = null;

            if (lstServiceGroup.Count > 0)
            {
                foreach (var group in lstServiceGroup)
                {
                    serviceVM.ServiceGroupId   = group.ServiceGroupId;
                    serviceVM.GroupName        = group.GroupName;
                    serviceVM.AppointmentColor = (int)group.AppointmentColor;
                    serviceVM.Description      = group.Description;
                    serviceVM.EntityId         = (int)group.EntityId;
                    lstServiceVM.Add(serviceVM);
                }
            }
            return(lstServiceVM);
        }
 public HttpResponseMessage Update(HttpRequestMessage request, ServiceGroupViewModel serviceGroupVM)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var dbServiceGroup = _serviceGroupService.GetById(serviceGroupVM.ID);
             dbServiceGroup.UpdateServiceGroup(serviceGroupVM);
             _serviceGroupService.update(dbServiceGroup);
             _serviceGroupService.Save();
             var responseData = Mapper.Map <ServiceGroup, ServiceGroupViewModel>(dbServiceGroup);
             response = request.CreateResponse(HttpStatusCode.Created, responseData);
         }
         return response;
     }));
 }
 public ValidationResponse CreateServiceGroup(ServiceGroupViewModel servicegroup)
 {
     throw new NotImplementedException();
 }