예제 #1
0
        public ActionResult MoveLevel1()
        {
            var model = new MoveServiceComponentLevel1ViewModel();

            // Get all functions for customer the move.
            if (_appUserContext.Current?.CurrentCustomer != null && _appUserContext.Current.CurrentCustomer.Id > 0)
            {
                model.ServiceFunctions = GetServiceFunctionHierarchy();
            }
            return(PartialView("_MoveL1", model));
        }
예제 #2
0
        public ActionResult MoveLevel1(MoveServiceComponentLevel1ViewModel model)
        {
            var result = GetJsonSuccessResponse();

            if (ModelState.IsValid)
            {
                if (_appUserContext.Current?.CurrentCustomer != null && _appUserContext.Current.CurrentCustomer.Id > 0)
                {
                    try
                    {
                        var component = _serviceComponentService
                                        .GetByCustomer(_appUserContext.Current.CurrentCustomer.Id)
                                        .SingleOrDefault(x => x.Id == model.ServiceComponentId);
                        if (component == null)
                        {
                            result = GetJsonErrorResponse(WebResources.ServiceComponentCannotBeFound);
                        }
                        else
                        {
                            component.ServiceFunctionId = model.DestinationServiceFunctionId;
                            component.UpdatedBy         = _contextManager.UserManager.Name;
                            component.UpdatedDate       = DateTime.Now;
                            if (component.ChildServiceComponents != null && component.ChildServiceComponents.Any())
                            {
                                // Update all of the underlying child service components
                                foreach (var childComponent in component.ChildServiceComponents)
                                {
                                    childComponent.ParentServiceComponentId = component.ParentServiceComponentId;
                                    childComponent.ServiceFunctionId        = model.DestinationServiceFunctionId;
                                    childComponent.UpdatedBy   = _contextManager.UserManager.Name;
                                    childComponent.UpdatedDate = DateTime.Now;
                                }
                            }
                            _serviceComponentService.Update(component);
                        }
                    }
                    catch (Exception ex)
                    {
                        result = GetJsonErrorResponse(ex.Message);
                    }
                }
            }
            else
            {
                result = GetJsonErrorResponse(ModelState.GetModelStateMesssages().First());
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }