コード例 #1
0
        public new static async Task <Response <Order> > CreateAsync(Order order, bool refreshFromDb = false, IList <string> navigationProperties = null)
        {
            Parallel.ForEach(order.OrderItems.Where(orderItem => orderItem.Id == Guid.Empty), orderItem => { orderItem.Id = Guid.NewGuid(); });

            if (!SalesValidator.ValidateOrder(order))
            {
                return(ResponseFactory <Order> .CreateResponse(false, ResponseCode.ErrorInvalidInput));
            }

            order.Date   = DateTime.Now;
            order.Status = OrderStatus.Created.ToInt();

            using (var orderRepository = DataLayerUnitOfWork.Repository <OrderRepository>())
            {
                var createdOrder =
                    await orderRepository.CreateAsync(order.CopyTo <DataLayer.Order>(), refreshFromDb, navigationProperties).ConfigureAwait(false);

                if (createdOrder == null)
                {
                    return(ResponseFactory <Order> .CreateResponse(false, ResponseCode.Error));
                }

                return(ResponseFactory <Order> .CreateResponse(true, ResponseCode.Success, createdOrder.CopyTo <Order>()));
            }
        }
コード例 #2
0
        public static async Task <Response> DeleteAsync(Guid id)
        {
            using (var repository = DataLayerUnitOfWork.Repository <TRepo>())
            {
                var result = await repository.DeleteAsync(id).ConfigureAwait(false);

                return(ResponseFactory.CreateResponse(result, result ? ResponseCode.Success : ResponseCode.ErrorInvalidInput));
            }
        }
コード例 #3
0
        public static async Task <Response> DeleteAsync(IList <TModel> modelCollection)
        {
            using (var repository = DataLayerUnitOfWork.Repository <TRepo>())
            {
                var entityCollection = modelCollection.CopyTo <TEntity>();

                var result = await repository.DeleteAsync(entityCollection).ConfigureAwait(false);

                return(ResponseFactory.CreateResponse(result, result ? ResponseCode.Success : ResponseCode.ErrorInvalidInput));
            }
        }
コード例 #4
0
        public static async Task <Response <IList <TModel> > > GetAllAsync(IList <string> navigationProperties = null)
        {
            using (var repository = DataLayerUnitOfWork.Repository <TRepo>())
            {
                var entities = await repository.GetAllAsync(navigationProperties).ConfigureAwait(false);

                if (entities == null)
                {
                    ResponseFactory <IList <TModel> > .CreateResponse(false, ResponseCode.Error);
                }

                return(ResponseFactory <IList <TModel> > .CreateResponse(true, ResponseCode.Success, entities.CopyTo <TModel>()));
            }
        }
コード例 #5
0
        public static async Task <Response <IList <Payroll> > > GetAllForClient(Guid clientId, IList <string> navigationProperties = null)
        {
            using (var payrollRepository = DataLayerUnitOfWork.Repository <PayrollRepository>())
            {
                var payrolls = await payrollRepository.GetAllForClient(clientId, navigationProperties).ConfigureAwait(false);

                if (payrolls == null)
                {
                    return(ResponseFactory <IList <Payroll> > .CreateResponse(false, ResponseCode.ErrorNotFound));
                }

                return(ResponseFactory <IList <Payroll> > .CreateResponse(true, ResponseCode.Success, payrolls.CopyTo <Payroll>()));
            }
        }
コード例 #6
0
        public static async Task <Response <IList <Order> > > GetAllAsync(string orderBy, bool orderAscending, IList <string> navigationProperties = null)
        {
            using (var orderRepository = DataLayerUnitOfWork.Repository <OrderRepository>())
            {
                var orders = await orderRepository.GetAllAsync(navigationProperties).ConfigureAwait(false);

                if (orders == null || orders.Count == 0)
                {
                    return(ResponseFactory <IList <Order> > .CreateResponse(true, ResponseCode.SuccessNoContent));
                }

                var sortedOrders = SortOrders(orders.CopyTo <Order>(), orderBy, orderAscending);

                return(ResponseFactory <IList <Order> > .CreateResponse(true, ResponseCode.Success, sortedOrders));
            }
        }
コード例 #7
0
        public static async Task <Response <TModel> > UpdateAsync(TModel model, bool refreshFromDb = false, IList <string> navigationProperties = null)
        {
            using (var repository = DataLayerUnitOfWork.Repository <TRepo>())
            {
                var entity = model.CopyTo <TEntity>();

                entity = await repository.UpdateAsync(entity, refreshFromDb, navigationProperties).ConfigureAwait(false);

                if (entity == null)
                {
                    return(ResponseFactory <TModel> .CreateResponse(false, ResponseCode.ErrorInvalidInput));
                }

                return(ResponseFactory <TModel> .CreateResponse(true, ResponseCode.Success, entity.CopyTo <TModel>()));
            }
        }
コード例 #8
0
        public new static async Task <Response <Order> > UpdateAsync(Order order, bool refreshFromDb = false, IList <string> navigationProperties = null)
        {
            if (!SalesValidator.ValidateOrder(order, false))
            {
                return(ResponseFactory <Order> .CreateResponse(false, ResponseCode.ErrorInvalidInput));
            }

            using (var orderRepository = DataLayerUnitOfWork.Repository <OrderRepository>())
            {
                var updatedOrder =
                    await orderRepository.UpdateAsync(order.CopyTo <DataLayer.Order>(), refreshFromDb, navigationProperties).ConfigureAwait(false);

                if (updatedOrder == null)
                {
                    return(ResponseFactory <Order> .CreateResponse(false, ResponseCode.Error));
                }

                return(ResponseFactory <Order> .CreateResponse(true, ResponseCode.Success, updatedOrder.CopyTo <Order>()));
            }
        }
コード例 #9
0
        public static async Task <Response <Order> > Cancel(Order order)
        {
            if (!SalesValidator.ValidateOrder(order, false))
            {
                return(ResponseFactory <Order> .CreateResponse(false, ResponseCode.ErrorInvalidInput));
            }

            order.Status = OrderStatus.Cancelled.ToInt();

            using (var orderRepository = DataLayerUnitOfWork.Repository <OrderRepository>())
            {
                var dbModel      = order.CopyTo <DataLayer.Order>();
                var updatedOrder = await orderRepository.UpdateAsync(dbModel).ConfigureAwait(false);

                if (updatedOrder == null)
                {
                    return(ResponseFactory <Order> .CreateResponse(false, ResponseCode.Error));
                }

                return(ResponseFactory <Order> .CreateResponse(true, ResponseCode.Success, order));
            }
        }