public DTOModels.Cost FromModelsCostToDTOModelCost(Models.Cost modelCost)
        {
            if (modelCost == null)
            {
                throw new ArgumentNullException(nameof(modelCost), "Couldn't transform Models.Cost to DTOModels.Cost object! Input parameter is null!");
            }

            DTOModels.Cost dtoModelCost = new DTOModels.Cost
            {
                Amount          = modelCost.Amount,
                AmountToDisplay = modelCost.Amount.ToString("N2"),
                Category        = modelCost.CostCategory?.CategoryName,
                CategoryId      = modelCost.CostCategoryId,
                CostSubCategory = modelCost.CostCategory?.SubCategoryName,
                Comment         = modelCost.Comment,
                Count           = modelCost.Count,
                Date            = modelCost.Date,
                Id        = modelCost.Id,
                PayType   = modelCost.PayType?.Name,
                PayTypeId = modelCost.PayTypeId,
                Store     = modelCost.Store?.Name,
                StoreId   = modelCost.StoreId
            };

            return(dtoModelCost);
        }
Example #2
0
        public async Task <IActionResult> Post(DTOModels.Cost cost)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                var modelCost = modelTransformer.FromDTOModelCostToModelCost(cost);

                var addedCost = await repository.AddCost(modelCost);

                if (addedCost == null)
                {
                    return(StatusCode((int)HttpStatusCode.InternalServerError, ServerMessages.INTERNAL_SERVER_ERROR));
                }

                return(StatusCode((int)HttpStatusCode.Created, modelTransformer.FromModelsCostToDTOModelCost(addedCost)));
            }
            catch (Exception ex)
            {
                logger.LogError(ex);
                return(StatusCode((int)HttpStatusCode.InternalServerError, ServerMessages.INTERNAL_SERVER_ERROR));
            }
        }
        public Models.Cost FromDTOModelCostToModelCost(DTOModels.Cost dtoModelCost)
        {
            if (dtoModelCost == null)
            {
                throw new ArgumentNullException(nameof(dtoModelCost), "Couldn't transform DTOModels.Cost to Models.Cost object! Input parameter is null!");
            }

            Models.Cost costModel = new Models.Cost
            {
                Amount         = dtoModelCost.Amount,
                Comment        = dtoModelCost.Comment,
                CostCategoryId = dtoModelCost.CategoryId,
                PayTypeId      = dtoModelCost.PayTypeId,
                StoreId        = dtoModelCost.StoreId,
                Id             = dtoModelCost.Id,
                Count          = dtoModelCost.Count,
                Date           = dtoModelCost.Date
            };

            return(costModel);
        }