Exemplo n.º 1
0
        public ActionResult MoveLevel2()
        {
            var model = new MoveServiceComponentLevel2ViewModel();

            // Get all functions for customer the move.
            if (_appUserContext.Current?.CurrentCustomer != null && _appUserContext.Current.CurrentCustomer.Id > 0)
            {
                model.ServiceComponents = GetServiceComponentHierarchy(null);
            }
            return(PartialView("_MoveL2", model));
        }
Exemplo n.º 2
0
        public ActionResult MoveLevel2(MoveServiceComponentLevel2ViewModel 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);
                        var destinationComponent = _serviceComponentService
                                                   .GetByCustomer(_appUserContext.Current.CurrentCustomer.Id)
                                                   .SingleOrDefault(x => x.Id == model.DestinationServiceComponentId);

                        if (component == null || destinationComponent == null)
                        {
                            result = GetJsonErrorResponse(WebResources.ServiceComponentCannotBeFound);
                        }
                        else
                        {
                            component.UpdatedBy                = _contextManager.UserManager.Name;
                            component.UpdatedDate              = DateTime.Now;
                            component.ServiceFunctionId        = destinationComponent.ServiceFunctionId;
                            component.ParentServiceComponentId = destinationComponent.Id;

                            if (destinationComponent.ChildServiceComponents == null)
                            {
                                destinationComponent.ChildServiceComponents = new List <ServiceComponent>();
                            }

                            destinationComponent.ChildServiceComponents.Add(component);
                            destinationComponent.UpdatedBy   = _contextManager.UserManager.Name;
                            destinationComponent.UpdatedDate = DateTime.Now;

                            _serviceComponentService.Update(destinationComponent);
                        }
                    }
                    catch (Exception ex)
                    {
                        result = GetJsonErrorResponse(ex.Message);
                    }
                }
            }
            else
            {
                result = GetJsonErrorResponse(ModelState.GetModelStateMesssages().First());
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }