public async Task <CategoryResponse> Add(CategoryAddRequest request)
        {
            var categoryToAdd = request.Model.MapToModel();

            categoryToAdd.FieldDefenitions?.Clear();
            categoryToAdd.FieldDefenitionGroups?.Clear();
            await BaseBeforeAddAsync(categoryToAdd, request.RequestOwner);

            await _dataSrv.AddAsync(categoryToAdd);

            request.Model.FieldDefenitions.ToList().MapToModel().ForEach(x =>
            {
                x.CategoryId = categoryToAdd.Id;
                _fieldDefentionFacade.PendToAdd(x);
            });
            request.Model.FieldDefenitionGroups.ToList().MapToModel().ForEach(x =>
            {
                x.CategoryId = categoryToAdd.Id;
                _unitOfWork.Add(x);
            });
            await _fieldDefentionFacade.SaveChangesAsync();

            await BaseAfterAddAsync(categoryToAdd, request.RequestOwner);

            HandleMetaData(request.Model.MetaData, categoryToAdd);
            await _unitOfWork.SaveChangesAsync();

            return(new CategoryResponse()
            {
                Access = ResponseAccess.Granted,
                Category = categoryToAdd.MapToViewModel()
            });
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Category> > PostCategory(CategoryAddRequest category)
        {
            var cat = _mapper.Map <Category>(category.Data);

            cat.Status = true;

            _context.Categories.Add(cat);
            await _context.SaveChangesAsync();

            var myCategory = _mapper.Map <DtoCategory>(cat);

            myCategory = CreateLinksForCategory(myCategory);
            var getResponse = new CategoryResponse
            {
                Value = myCategory,
                Meta  = new DtoMeta
                {
                    Date       = DateTimeOffset.UtcNow,
                    ResponseId = Guid.NewGuid(),
                    Status     = Status.Succeeded
                }
            };


            return(CreatedAtAction("GetCategory", new { id = cat.CategoryId }, getResponse));
        }
Exemplo n.º 3
0
        public async Task <CategoryDTO> Add(CategoryAddRequest model)
        {
            var oCategory = _mapper.Map <Category>(model);

            if (await _repository.Add(oCategory))
            {
                return(_mapper.Map <CategoryDTO>(oCategory));
            }

            return(null);
        }
 public async Task<StatusData<byte?>> InsertCategory(CategoryAddRequest request, SystemSession session)
 {
     var userCategory = new UserCategory { UserId = session.UserId.ToString(), Name = request.Name, Description = request.Description };
     var result = new StatusData<byte?>();
     var friends = request.Friends != null && request.Friends.Any() ? String.Join(",", request.Friends) : null;
     var serviceResponse = await Task.Factory.StartNew(() => Client.UserService.createNewCategory(userCategory, friends, session.GetSession())).ConfigureAwait(false);
     result.Data = (byte?)serviceResponse.UserCategoryTypeId;
     result.Message = serviceResponse.DbStatusMsg;
     result.Status = (SystemDbStatus)serviceResponse.DbStatusCode;
     result.SubStatus = serviceResponse.DbSubStatusCode;
     return result;
 }
        public async Task <IActionResult> Add(CategoryAddRequest model)
        {
            Response oR = new Response();

            try
            {
                if (!ModelState.IsValid)
                {
                    oR.Status  = StatusCodes.Status400BadRequest;
                    oR.Message = Messages.ValidationsFailed;
                    oR.Data    = GetModelErrors(ModelState);

                    return(BadRequest(oR));
                }

                if (!await _service.ExistsName(model.Name))
                {
                    ModelState.AddModelError("Name", Messages.ResourceNameAlreadyExists);

                    oR.Status  = StatusCodes.Status400BadRequest;
                    oR.Message = Messages.ValidationsFailed;
                    oR.Data    = GetModelErrors(ModelState);

                    return(BadRequest(oR));
                }

                var oCategory = await _service.Add(model);

                if (oCategory != null)
                {
                    oR.Status = StatusCodes.Status201Created;
                    oR.Data   = oCategory;

                    return(CreatedAtAction(nameof(GetById), new { id = oCategory.Id }, oR));
                }
                else
                {
                    oR.Status  = StatusCodes.Status500InternalServerError;
                    oR.Message = Messages.InternalServerError;

                    return(StatusCode(StatusCodes.Status500InternalServerError, oR));
                }
            }
            catch (Exception ex)
            {
                oR.Status  = StatusCodes.Status500InternalServerError;
                oR.Message = Messages.InternalServerError;

                return(StatusCode(StatusCodes.Status500InternalServerError, oR));
            }
        }
        public async Task <StatusData <byte?> > InsertCategory(CategoryAddRequest request, SystemSession session)
        {
            var userCategory = new UserCategory {
                UserId = session.UserId.ToString(), Name = request.Name, Description = request.Description
            };
            var result          = new StatusData <byte?>();
            var friends         = request.Friends != null && request.Friends.Any() ? String.Join(",", request.Friends) : null;
            var serviceResponse = await Task.Factory.StartNew(() => Client.UserService.createNewCategory(userCategory, friends, session.GetSession())).ConfigureAwait(false);

            result.Data      = (byte?)serviceResponse.UserCategoryTypeId;
            result.Message   = serviceResponse.DbStatusMsg;
            result.Status    = (SystemDbStatus)serviceResponse.DbStatusCode;
            result.SubStatus = serviceResponse.DbSubStatusCode;
            return(result);
        }
Exemplo n.º 7
0
        public ActionResult Add(CategoryAddRequest request)
        {
            request.isActive = true;
            AdminCategoryIndexModel adminCategoryIndexModel = new AdminCategoryIndexModel();

            if (!ModelState.IsValid)
            {
                adminCategoryIndexModel.CategoryAddRequest = request;
                return(RedirectToAction("Index", "Category", adminCategoryIndexModel));
            }
            CommonResponse addResponse = WebApiOperation.SendPost <CategoryAddRequest, CommonResponse>(Constants.PRODUCT_API_BASE_URI, Constants.PRODUCT_API_ADD_CATEGORY, request);

            TempData["ResponseCode"]    = addResponse.Code;
            TempData["ResponseMessage"] = addResponse.Message;
            //mesajlar sayfaya donulecek
            return(RedirectToAction("Index", "Category", adminCategoryIndexModel));
        }
Exemplo n.º 8
0
        public CategoryResponse Create(CategoryAddRequest request)
        {
            using (var adapter = DataAccessAdapterFactory.NewDataAccessAdapter())
            {
                OnBeforeCategoryAddRequest(adapter, request);

                var entity = request.FromDto();
                entity.IsNew = true;

                if (adapter.SaveEntity(entity, true))
                {
                    OnAfterCategoryAddRequest(adapter, request);
                    return(new CategoryResponse(entity.ToDto()));
                }
            }

            throw new InvalidOperationException();
        }
        public async Task <HttpResponseMessage> Put([FromBody] CategoryAddRequest request)
        {
            var response = await _service.InsertCategory(request, Request.GetSession()).ConfigureAwait(false);

            return(Request.SystemResponse(response.Status, new { response.Data }, message: response.Message));
        }
 public AdminCategoryIndexModel()
 {
     CategoryAddRequest    = new CategoryAddRequest();
     CategoryModelResponse = new CategoryModelResponse();
 }
Exemplo n.º 11
0
 partial void OnAfterCategoryAddRequest(IDataAccessAdapter adapter, CategoryAddRequest request);
Exemplo n.º 12
0
 public Task<StatusData<byte?>> InsertCategory(CategoryAddRequest request, SystemSession session)
 {
     return _jUnitOfWork.Category.InsertCategory(request, session);
 }
Exemplo n.º 13
0
 public Task <StatusData <byte?> > InsertCategory(CategoryAddRequest request, SystemSession session)
 {
     return(_jUnitOfWork.Category.InsertCategory(request, session));
 }