コード例 #1
0
        public async Task <ErrorRepsonse <TreasuryDto> > Create(CreateTreasuryDto createTreasuryDto)
        {
            if (await _uintOfWork.Repository <Treasury>().Any(c => c.Id == createTreasuryDto.UserId))
            {
                return(new ErrorRepsonse <TreasuryDto>("يوجد صندوق لهذا المتسخدم "));
            }
            var treaury = _mapper.Map <Treasury>(createTreasuryDto);
            await _uintOfWork.BegeinTransaction();

            try
            {
                await _uintOfWork.Add(treaury);

                if (createTreasuryDto.Amount != 0)
                {
                    var cashMovment = _mapper.Map <CashMovment>(createTreasuryDto);
                    cashMovment.CreatedBy = _userService.AuthoticateUserName();
                    var history = _mapper.Map <TreasuryHistory>(cashMovment);
                    cashMovment.TreasuryHistories.Add(history);
                    await _uintOfWork.Add(cashMovment);

                    history.CashMovment = cashMovment;
                    treaury.TreasuryHistories.Add(history);
                }
                await _uintOfWork.Commit();

                var dto = _mapper.Map <TreasuryDto>(treaury);
                dto.History = new PagingResualt <IEnumerable <TreasuryHistoryDto> >()
                {
                    Total = treaury.TreasuryHistories.Count,
                    Data  = _mapper.Map <TreasuryHistoryDto[]>(treaury.TreasuryHistories)
                };
                return(new ErrorRepsonse <TreasuryDto>(dto));
            }
            catch (Exception ex)
            {
                await _uintOfWork.RoleBack();

                return(new ErrorRepsonse <TreasuryDto>("حصل خطأ ما ")
                {
                });
            }
        }
コード例 #2
0
        public async Task <ErrorRepsonse <ClientDto> > GivePoints(GiveOrDiscountPointsDto giveOrDiscountPointsDto)
        {
            var client = await _uintOfWork.Repository <Client>().GetById(giveOrDiscountPointsDto.ClientId);

            await _uintOfWork.BegeinTransaction();

            try
            {
                string sen = "";
                if (giveOrDiscountPointsDto.IsGive)
                {
                    client.Points += giveOrDiscountPointsDto.Points;
                    sen           += $"تم إهدائك {giveOrDiscountPointsDto.Points} نقاط";
                }
                else
                {
                    client.Points -= giveOrDiscountPointsDto.Points;
                    sen           += $"تم خصم {giveOrDiscountPointsDto.Points} نقاط منك";
                }
                Notfication notfication = new Notfication()
                {
                    ClientId = client.Id,
                    Note     = sen,
                };
                await _uintOfWork.Repository <Client>().Update(client);

                await _uintOfWork.Repository <Notfication>().AddAsync(notfication);

                await _uintOfWork.Commit();

                RemoveCash();
                return(new ErrorRepsonse <ClientDto>()
                {
                    Data = _mapper.Map <ClientDto>(client)
                });
            }
            catch (Exception ex)
            {
                await _uintOfWork.RoleBack();

                throw ex;
            }
        }
コード例 #3
0
        public async Task <ErrorResponse <string, IEnumerable <string> > > ReceiptOfTheStatusOfTheDeliveredShipment(IEnumerable <ReceiptOfTheStatusOfTheDeliveredShipmentWithCostDto> receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos)
        {
            var moneyPlacedes = await _uintOfWork.Repository <MoenyPlaced>().GetAll();

            var orderPlacedes = await _uintOfWork.Repository <OrderPlaced>().GetAll();

            var outSideCompny = moneyPlacedes.First(c => c.Id == (int)MoneyPalcedEnum.OutSideCompany).Name;
            var response      = new ErrorResponse <string, IEnumerable <string> >();

            if (!receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos.All(c => c.OrderplacedId == OrderplacedEnum.Way || c.OrderplacedId == OrderplacedEnum.Delivered || c.OrderplacedId == OrderplacedEnum.PartialReturned))
            {
                var wrongData    = receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos.Where(c => !(c.OrderplacedId == OrderplacedEnum.Way || c.OrderplacedId == OrderplacedEnum.Delivered || c.OrderplacedId == OrderplacedEnum.PartialReturned));
                var worngDataIds = wrongData.Select(c => c.Id);
                var worngOrders  = await _uintOfWork.Repository <Order>().GetAsync(c => worngDataIds.Contains(c.Id));

                List <string> errors = new List <string>();
                foreach (var item in receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos)
                {
                    string code = worngOrders.Where(c => c.Id == item.Id).FirstOrDefault()?.Code;
                    errors.Add($"لا يمكن وضع حالة الشحنة {OrderPlacedEnumToString(item.OrderplacedId)} للشحنة ذات الرقم : {code}");
                }
                response.Errors = errors;
                return(response);
            }
            List <Notfication> notfications      = new List <Notfication>();
            List <Notfication> addednotfications = new List <Notfication>();

            var ids = new HashSet <int>(receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos.Select(c => c.Id));

            var orders = await _uintOfWork.Repository <Order>().GetAsync(c => ids.Contains(c.Id));

            var repatedOrders = orders.Where(order => receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos.Any(r => r.EqualToOrder(order))).ToList();

            orders = orders.Except(repatedOrders).ToList();
            var exptedOrdersIds = repatedOrders.Select(c => c.Id);

            receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos = receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos.Where(c => !exptedOrdersIds.Contains(c.Id));
            if (!receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos.Any())
            {
                return(new ErrorResponse <string, IEnumerable <string> >());
            }
            List <OrderLog> logs = new List <OrderLog>();

            foreach (var item in receiptOfTheStatusOfTheDeliveredShipmentWithCostDtos)
            {
                var order = orders.First(c => c.Id == item.Id);
                logs.Add(order);
                order.MoenyPlacedId = (int)item.MoenyPlacedId;
                order.OrderplacedId = (int)item.OrderplacedId;
                order.Note          = item.Note;
                if (order.DeliveryCost != item.DeliveryCost)
                {
                    if (order.OldDeliveryCost == null)
                    {
                        order.OldDeliveryCost = order.DeliveryCost;
                    }
                }
                order.DeliveryCost = item.DeliveryCost;
                order.AgentCost    = item.AgentCost;
                order.SystemNote   = "ReceiptOfTheStatusOfTheDeliveredShipment";
                if (order.IsClientDiliverdMoney)
                {
                    switch (order.OrderplacedId)
                    {
                    case (int)OrderplacedEnum.Delivered:
                    {
                        if (decimal.Compare(order.Cost, item.Cost) != 0)
                        {
                            if (order.OldCost == null)
                            {
                                order.OldCost = order.Cost;
                            }
                            order.Cost = item.Cost;
                        }
                        var payForClient = order.ShouldToPay();

                        if (decimal.Compare(payForClient, (order.ClientPaied ?? 0)) != 0)
                        {
                            order.OrderStateId = (int)OrderStateEnum.ShortageOfCash;
                            if (order.MoenyPlacedId == (int)MoneyPalcedEnum.Delivered)
                            {
                                order.MoenyPlacedId = (int)MoneyPalcedEnum.InsideCompany;
                            }
                        }
                        else
                        {
                            order.OrderStateId = (int)OrderStateEnum.Finished;
                        }
                    }
                    break;

                    case (int)OrderplacedEnum.PartialReturned:
                    {
                        if (order.OldCost == null)
                        {
                            order.OldCost = order.Cost;
                        }
                        order.Cost         = item.Cost;
                        order.OrderStateId = (int)OrderStateEnum.ShortageOfCash;
                    }
                    break;
                    }
                }
                else
                {
                    if (order.Cost != item.Cost)
                    {
                        if (order.OldCost == null)
                        {
                            order.OldCost = order.Cost;
                        }
                        order.Cost = item.Cost;
                    }
                }
                if (order.MoenyPlacedId == (int)MoneyPalcedEnum.InsideCompany)
                {
                    order.ApproveAgentEditOrderRequests.Clear();
                }
                order.MoenyPlaced = moneyPlacedes.First(c => c.Id == order.MoenyPlacedId);
                order.Orderplaced = orderPlacedes.First(c => c.Id == order.OrderplacedId);
            }

            await _uintOfWork.BegeinTransaction();

            try
            {
                await _uintOfWork.UpdateRange(orders);

                await _uintOfWork.AddRange(logs);

                await _notificationService.SendOrderReciveNotifcation(orders);

                var receiptOfTheOrderStatus = new ReceiptOfTheOrderStatus
                {
                    CreatedOn = DateTime.UtcNow,
                    RecvierId = _userService.AuthoticateUserId()
                };
                var receiptOfTheOrderStatusDetalis = new List <ReceiptOfTheOrderStatusDetali>();
                foreach (var order in orders)
                {
                    receiptOfTheOrderStatusDetalis.Add(new ReceiptOfTheOrderStatusDetali()
                    {
                        OrderCode     = order.Code,
                        ClientId      = order.ClientId,
                        Cost          = order.Cost,
                        AgentCost     = order.AgentCost,
                        AgentId       = (int)order.AgentId,
                        MoneyPlacedId = order.MoenyPlacedId,
                        OrderPlacedId = order.OrderplacedId,
                        OrderStateId  = order.OrderStateId,
                    });
                }
                receiptOfTheOrderStatus.ReceiptOfTheOrderStatusDetalis = receiptOfTheOrderStatusDetalis;
                await _uintOfWork.Add(receiptOfTheOrderStatus);

                await _treasuryService.IncreaseAmountByOrderFromAgent(receiptOfTheOrderStatus);

                await _uintOfWork.Commit();

                return(response);
            }
            catch (Exception ex)
            {
                await _uintOfWork.RoleBack();

                return(new ErrorResponse <string, IEnumerable <string> >("حدث خطأ ما "));
            }
        }