Пример #1
0
        public void Add()
        {
            var type = new ArticleType()
            {
                Description  = "Test",
                Name         = "Test",
                ModifiedById = null,
                CompanyId    = 1,
                Resources    = new List <ArticleTypeResource>
                {
                    new ArticleTypeResource {
                        Culture = Culture.English, Value = "Test"
                    },
                    new ArticleTypeResource {
                        Culture = Culture.Spanish, Value = "Prueba"
                    },
                    new ArticleTypeResource {
                        Culture = Culture.Hindi, Value = "pareekshan"
                    }
                }
            };
            var result = _typeService.Add(type);

            Assert.IsNotNull(result);
        }
        public IActionResult SaveEntity(TypeViewModel productVm)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                ErrorMesage e = new ErrorMesage();
                if (productVm.SortOrder == 0)
                {
                    e.Message = "Vui lòng nhập SortOrder";
                    e.Error   = true;
                    return(new BadRequestObjectResult(e));
                }

                return(new BadRequestObjectResult(allErrors));
            }
            else
            {
                productVm.SeoAlias = TextHelper.ToUnsignString(productVm.Name);
                if (productVm.Id == 0)
                {
                    _typeService.Add(productVm);
                }
                else
                {
                    _typeService.Update(productVm);
                }
                _typeService.Save();
                return(new OkObjectResult(productVm));
            }
        }
Пример #3
0
 public ApiResponseViewModel Create(Model.Models.Type obj)
 {
     if (HttpContext.Current.Session["UserLogged"] == null)
     {
         return(CommonConstants.accessDenied);
     }
     return(_TypeService.Add(obj));
 }
Пример #4
0
 public IActionResult Create([FromBody] TypeModel model)
 {
     if (!ModelState.IsValid || model == null || model.Id.HasValue)
     {
         return(BadRequest());
     }
     _typeService.Add(_mapper.Map <TypeModel, TypeDTO>(model));
     return(Ok());
 }
Пример #5
0
        public IActionResult CreateType([FromBody] CreateTypeRequest request)
        {
            Type type = new Type();

            type.Name     = request.Name;
            type.IsActive = true;
            _typeService.Add(type);
            return(Ok());
        }
Пример #6
0
 public IActionResult Add([FromBody] TypeCreationDto request)
 {
     try
     {
         _service.Add(request.ToEntity());
         return(Ok());
     }
     catch (Exception e)
     {
         _logger.LogError(-1, e, String.Format(LogErrorText, e.Message));
         return(BadRequest(String.Format(BadRequestText, "adding type")));
     }
 }
Пример #7
0
        public async Task <JsonResult> CreateType(Type type)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = await _userManager.GetUserAsync(User);

                    await _typeService.Add(user, type);
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }

                return(Json(null));
            }
            return(Json(null));
        }
Пример #8
0
        public IActionResult SaveEntity(TypeViewModel typeVm)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(allErrors));
            }

            if (typeVm.Id == 0)
            {
                _typeService.Add(typeVm);
            }
            else
            {
                _typeService.Update(typeVm);
            }

            _typeService.Save();
            return(new OkObjectResult(typeVm));
        }
Пример #9
0
 public HttpResponseMessage Create(HttpRequestMessage request, TypeViewModel typeVm)
 {
     if (ModelState.IsValid)
     {
         var newType = new Model.Models.Type();
         newType.UpdateType(typeVm);
         try
         {
             _typeService.Add(newType);
             _typeService.Save();
             return(request.CreateResponse(HttpStatusCode.OK, typeVm));
         }
         catch (NameDuplicatedException dex)
         {
             return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
         }
     }
     else
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }