public ProductType Post([FromBody] ProductTypeDTO value)
        {
            TryValidateModel(value);
            var productType = service.Create(mapper.Map <ProductType>(value));

            return(mapper.Map <ProductType>(productType));
        }
        public IActionResult Create([FromBody] ProductTypeIn pTypeIn)
        {
            try
            {
                var pTypeOut = productTypeService.Create(pTypeIn);
                return(Json(pTypeOut));
            }
            catch (ArgumentException ex)
            {
                Response.StatusCode = 403;
                var msg = new JsonMessage("Исключение на свойстве: " + ex.Message, "");

                return(Json(msg));
            }
        }
        public ActionResult Create(ProductTypeIndexViewModel model)
        {
            try
            {
                if (CurrentUser.UserRole == Enums.UserRole.Viewer || IsCreatorPRD(CurrentUser.USER_ID) || CurrentUser.UserRole == Enums.UserRole.Controller)
                {
                    AddMessageInfo("Operation not allowed", Enums.MessageInfoType.Error);
                    return(RedirectToAction("Index"));
                }

                var obj = model.ViewModel;
                if (obj.IsDeleted == true)
                {
                    obj.IsDeleted = false;
                }
                else
                {
                    obj.IsDeleted = true;
                }
                obj.CreatedBy    = CurrentUser.USER_ID;
                obj.CreatedDate  = DateTime.Now;
                obj.ModifiedBy   = CurrentUser.USER_ID;
                obj.ModifiedDate = DateTime.Now;
                model.ViewModel  = obj;

                if (!ModelState.IsValid)
                {
                    AddMessageInfo("Operation not allowed", Enums.MessageInfoType.Error);
                }
                else
                {
                    obj.ApprovalStatus = _refService.GetReferenceByKey(ReferenceKeys.ApprovalStatus.Draft).REFF_ID;

                    var inserted = _productTypeService.Create(Mapper.Map <CustomService.Data.MASTER_PRODUCT_TYPE>(obj), (int)Enums.MenuList.ProductType, (int)Enums.ActionType.Created, (int)CurrentUser.UserRole, CurrentUser.USER_ID);

                    AddMessageInfo(Constans.SubmitMessage.Saved, Enums.MessageInfoType.Success);

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                AddMessageInfo("Save Failed : " + ex.Message, Enums.MessageInfoType.Error);
            }

            model = GenerateProperties(model, true);
            return(View(model));
        }
示例#4
0
        public ActionResult Save(ProductTypeModel model, string @return)
        {
            ProductType productType = null;

            if (model.Id == 0)
            {
                productType = _productTypeService.Create(new CreateProductTypeRequest
                {
                    Name          = model.Name,
                    SkuAlias      = model.SkuAlias,
                    CustomFields  = model.CustomFieldDefinitions,
                    VariantFields = model.VariantFieldDefinitions
                });
            }
            else
            {
                productType = _productTypeService.Update(new UpdateProductTypeRequest(model.Id)
                {
                    Name          = model.Name,
                    SkuAlias      = model.SkuAlias,
                    CustomFields  = model.CustomFieldDefinitions,
                    VariantFields = model.VariantFieldDefinitions
                });
            }

            if (model.IsEnabled)
            {
                _productTypeService.Enable(productType);
            }
            else
            {
                _productTypeService.Disable(productType);
            }

            return(AjaxForm().RedirectTo(@return));
        }