コード例 #1
0
        public HttpResponseMessage Create(HttpRequestMessage request, FunctionViewModel functionVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newFunction = new Function();
                    if (_functionService.CheckExistedId(functionVm.ID))
                    {
                        return request.CreateErrorResponse(HttpStatusCode.BadRequest, "Id đã tồn tại");
                    }
                    else
                    {
                        if (functionVm.ParentId == "")
                        {
                            functionVm.ParentId = null;
                        }
                        newFunction.UpdateFunction(functionVm);
                        _functionService.Create(newFunction);
                        _functionService.Save();
                        response = request.CreateResponse(HttpStatusCode.OK, functionVm);
                    }
                }

                return response;
            }));
        }
コード例 #2
0
 public HttpResponseMessage Create(HttpRequestMessage request, FunctionViewModel functionViewModel)
 {
     if (ModelState.IsValid)
     {
         var model = new Function();
         try
         {
             bool check = _functionService.CheckExistedId(functionViewModel.ID);
             if (check == true)
             {
                 return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Dữ liệu đã tồn tại"));
             }
             if (functionViewModel.ParentId == "")
             {
                 functionViewModel.ParentId = null;
             }
             model.UpdateFunction(functionViewModel);
             _functionService.Create(model);
             _functionService.Save();
             return(request.CreateResponse(HttpStatusCode.OK, functionViewModel));
         }
         catch (Exception ex)
         {
             return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
         }
     }
     else
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
コード例 #3
0
        public HttpResponseMessage Create(HttpRequestMessage request, FunctionViewModel functionViewModel)
        {
            if (ModelState.IsValid)
            {
                var newFunction = new Function();
                try
                {
                    if (_functionService.CheckExistedId(functionViewModel.ID))
                    {
                        return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "ID đã tồn tại"));
                    }
                    else
                    {
                        if (functionViewModel.ParentId == "")
                        {
                            functionViewModel.ParentId = null;
                        }
                        newFunction.UpdateFunction(functionViewModel);

                        _functionService.Create(newFunction);
                        _functionService.Save();
                        return(request.CreateResponse(HttpStatusCode.OK, functionViewModel));
                    }
                }
                catch (Exception dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
コード例 #4
0
        public HttpResponseMessage Create(HttpRequestMessage request, FunctionViewModel functionViewModel)
        {
            Func <HttpResponseMessage> func = () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    Function newFunctionDb = new Function();
                    if (_functionService.CheckExistedId(functionViewModel.ID))
                    {
                        response = request.CreateErrorResponse(HttpStatusCode.BadRequest, "ID đã tồn tại");
                    }
                    else
                    {
                        if (functionViewModel.ParentId == "")
                        {
                            functionViewModel.ParentId = null;
                        }
                        newFunctionDb.UpdateFunction(functionViewModel);
                        _functionService.Create(newFunctionDb);
                        _functionService.SaveChange();
                        response = request.CreateResponse(HttpStatusCode.Created, functionViewModel);
                    }
                }
                return(response);
            };

            return(CreateHttpResponse(request, func));
        }
コード例 #5
0
        public HttpResponseMessage Create(HttpRequestMessage request, FunctionViewModel functionViewModel)
        {
            if (ModelState.IsValid)
            {
                var newFunction            = new Function();
                var identity               = (ClaimsIdentity)User.Identity;
                IEnumerable <Claim> claims = identity.Claims;
                try
                {
                    if (_functionService.CheckExistedId(functionViewModel.ID))
                    {
                        return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "ID đã tồn tại"));
                    }
                    else
                    {
                        if (functionViewModel.ParentId == "")
                        {
                            functionViewModel.ParentId = null;
                        }
                        newFunction.UpdateFunction(functionViewModel);

                        _functionService.Create(newFunction);
                        _functionService.Save();
                        Log log = new Log()
                        {
                            AppUserId = claims.FirstOrDefault().Value,
                            Content   = Notification.CREATE_FUNCTION,
                            Created   = DateTime.Now
                        };
                        _logService.Create(log);
                        _logService.Save();
                        return(request.CreateResponse(HttpStatusCode.OK, functionViewModel));
                    }
                }
                catch (Exception dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
コード例 #6
0
 public IActionResult SaveEntity(FunctionViewModel functionVm)
 {
     if (!ModelState.IsValid)
     {
         IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
         return(new BadRequestObjectResult(allErrors));
     }
     else
     {
         if (string.IsNullOrWhiteSpace(functionVm.Id))
         {
             _functionService.Create(functionVm);
         }
         else
         {
             _functionService.Update(functionVm);
         }
         _functionService.Save();
         return(new OkObjectResult(functionVm));
     }
 }
コード例 #7
0
        public IActionResult AddFunction([FromBody] FunctionDto functionDto)
        {
            var function = _mapper.Map <Function>(functionDto);

            //Company company = new Company()
            //{
            //    Name = companyDto.Name,
            //    CategoryId = companyDto.CategoryId,
            //    Section = companyDto.Section,
            //    FunctionCode = companyDto.FunctionCode
            //};

            try
            {
                _service.Create(function);
                return(Ok("Records Added Successfully.. "));
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
コード例 #8
0
 public async Task <IActionResult> Create([FromBody] SaveFunctionResource resource)
 {
     return(await _functionService.Create(resource));
 }