示例#1
0
        public HttpResponseMessage ChangeBusinessEntity([FromBody] BusinessEntityIModel businessEntity)
        {
            var serviceResult = _searchService.ChangeBusinessEntity(businessEntity);

            if (!serviceResult.Success)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, serviceResult.ex.Message, serviceResult.ex));
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
        public ServiceResult <BusinessEntityOModel> ChangeBusinessEntity(BusinessEntityIModel businessEntity)
        {
            try
            {
                var serviceResult = Change <BusinessEntity, BusinessEntityOModel>(
                    _priceCalculationUoW._businessEntityRepository,
                    businessEntity.MapToDataModel <BusinessEntity>());

                _priceCalculationUoW.Commit();

                return(serviceResult);
            }
            catch (Exception ex)
            {
                return(new ServiceResult <BusinessEntityOModel>
                {
                    Success = false,
                    ex = ex
                });
            }
        }
示例#3
0
        // Maps a ViewModel to DataModel
        public static T MapToDataModel <T>(this BaseViewModel src)
            where T : class, BaseDataModel
        {
            var mapType = typeof(T);

            switch (mapType.Name)
            {
            case "BusinessItem":
            {
                var srcObj = new BusinessItemIModel();
                srcObj.CopyPropertiesFrom(src);

                var mapObj = new BusinessItem
                {
                    Id     = srcObj.Id,
                    ItemId = srcObj.ItemId,
                    Item   = new Item
                    {
                        Id          = srcObj.ItemId,
                        Name        = srcObj.Name,
                        Description = srcObj.Description,
                        GroupId     = srcObj.GroupId,
                        Group       = null
                    },
                    Quantity = srcObj.Quantity,
                    Prices   = new List <Price>
                    {
                        new Price
                        {
                            Type           = PriceType.Cost,
                            Amount         = srcObj.PriceCost,
                            BusinessItemId = srcObj.Id,
                            BusinessItem   = null
                        }
                    },
                    DateOfProduction = DateTime.ParseExact(srcObj.DateOfProduction, "dd/MM/yyyy", new CultureInfo("en-US")),
                    DateOfLastSold   = DateTime.ParseExact(srcObj.DateOfLastSold, "dd/MM/yyyy", new CultureInfo("en-US")),
                    Catalogues       = null,
                };

                var map = (T)Activator.CreateInstance(mapType);
                map.CopyPropertiesFrom(mapObj);

                return(map);
            }

            case "BusinessEntity":
            {
                var srcObj = new BusinessEntityIModel();
                srcObj.CopyPropertiesFrom(src);

                var mapObj = new BusinessEntity
                {
                };

                var map = (T)Activator.CreateInstance(mapType);
                map.CopyPropertiesFrom(mapObj);

                return(map);
            }

            default:
                throw new Exception($"No implementation to map {mapType.Name}!");
            }
        }