public async Task <IResponse <BankAccount> > AddAsync(BankAccount model)
        {
            await _appUow.BankAccountRepo.AddAsync(model);

            var saveResult = await _appUow.ElkSaveChangesAsync();

            return(new Response <BankAccount> {
                Result = model, IsSuccessful = saveResult.IsSuccessful, Message = saveResult.Message
            });
        }
        public async Task <IResponse <Address> > AddAsync(Address model)
        {
            await _appUow.AddressRepo.AddAsync(model);

            var saveResult = await _appUow.ElkSaveChangesAsync();

            return(new Response <Address> {
                Result = model, IsSuccessful = saveResult.IsSuccessful, Message = saveResult.Message
            });
        }
        public async Task <IResponse <ProductCategory> > AddAsync(ProductCategory model)
        {
            await _productCategoryRepo.AddAsync(model);

            var saveResult = await _appUow.ElkSaveChangesAsync();

            return(new Response <ProductCategory> {
                Result = model, IsSuccessful = saveResult.IsSuccessful, Message = saveResult.Message
            });
        }
        public async Task <IResponse <string> > DeleteAsync(int id)
        {
            try
            {
                var asset = await _lossAssetRepo.FindAsync(id);

                if (asset == null)
                {
                    return new Response <string> {
                               Message = ServiceMessage.RecordNotExist
                    }
                }
                ;
                _lossAssetRepo.Delete(asset);
                var delete = await _appUow.ElkSaveChangesAsync();

                if (File.Exists(asset.PhysicalPath))
                {
                    File.Delete(asset.PhysicalPath);
                }
                return(new Response <string> {
                    IsSuccessful = delete.IsSuccessful, Message = delete.Message
                });
            }
            catch (Exception e)
            {
                FileLoger.Error(e);
                return(new Response <string> {
                    Message = ServiceMessage.Error
                });
            }
        }
Beispiel #5
0
        public async Task <IResponse <Guid> > AddRangeAsync(IList <TempOrderDetail> model)
        {
            var id = Guid.NewGuid();

            for (var i = 0; i < model.Count; i++)
            {
                model[i].BasketId = id;
            }
            await _tempOrderDetailRepo.AddRangeAsync(model);

            var save = await _appUOW.ElkSaveChangesAsync();

            return(new Response <Guid> {
                Result = id, IsSuccessful = save.IsSuccessful, Message = save.Message
            });
        }
Beispiel #6
0
        public async Task<IResponse<int>> Add(int orderId)
        {
            var order = await _appUOW.OrderRepo.FirstOrDefaultAsync(x => x.OrderId == orderId, new List<System.Linq.Expressions.Expression<System.Func<Order, object>>> { x => x.FromAddress, x => x.ToAddress, x => x.User });
            if (order == null) return new Response<int> { Message = ServiceMessage.RecordNotExist };
            UserComment userComment = null;
            try { userComment = order.UserComment.DeSerializeJson<UserComment>(); } catch { }
            using var deliveryPriceHttp = new HttpClient();
            var callDeliveryAPI = await deliveryPriceHttp.PostAsync(_configuration["Delivery:Add"], new StringContent(new DeliveryOrderDTO
            {
                Addresses = new List<DeliveryOrderLocationDTO>
                {
                    new DeliveryOrderLocationDTO
                    {
                        Type = "origin",
                        Lat = order.FromAddress.Latitude,
                        Lng = order.FromAddress.Longitude
                    },
                    new DeliveryOrderLocationDTO
                    {
                        Type = "destination",
                        Lat = order.ToAddress.Latitude,
                        Lng = order.ToAddress.Longitude,
                        Description=order.OrderComment,
                        PersonFullName =userComment?.Reciever,
                        PersonPhone = userComment?.RecieverMobileNumber
                    }
                }
            }.SerializeToJson(), Encoding.UTF8, "application/json"));
            if (!callDeliveryAPI.IsSuccessStatusCode)
            {
                FileLoger.Info($"Add Delivery Api Failed: {callDeliveryAPI.StatusCode}");
                return new Response<int> { IsSuccessful = false };
            }
            var add = (await callDeliveryAPI.Content.ReadAsStringAsync()).DeSerializeJson<Response<OrderResult>>();
            if (!add.IsSuccessful)
            {
                FileLoger.Info($"Add Delivery Api Failed: {add.Message}");
                return new Response<int> { IsSuccessful = false };
            }
            order.DeliveryDetailJson = new
            {
                add.Result.OrderId,
                add.Result.PayAtDestination,
                add.Result.OrderToken

            }.SerializeToJson();
            _appUOW.OrderRepo.Update(order);
            var update = await _appUOW.ElkSaveChangesAsync();
            if (!update.IsSuccessful)
            {
                FileLoger.Info($"Update Ordder DeliveryDetailJson Failed: {update.Message}");
                return new Response<int> { IsSuccessful = false };
            }
            return new Response<int> { IsSuccessful = true };
        }
Beispiel #7
0
        public async Task <IResponse <Payment> > Add(PaymentAddModel model)
        {
            var payment = new Payment
            {
                OrderId          = model.OrderId,
                PaymentGatewayId = model.GatewayId,
                PaymentStatus    = PaymentStatus.Insert,
                Price            = model.Amount,
                TransactionId    = model.TransactionId
            };
            await _paymentRepo.AddAsync(payment);

            var saveResult = await _appUow.ElkSaveChangesAsync();

            return(new Response <Payment>
            {
                IsSuccessful = saveResult.IsSuccessful,
                Message = saveResult.IsSuccessful ? string.Empty : saveResult.Message,
                Result = payment
            });
        }
Beispiel #8
0
        public async Task <IResponse <Loss> > AddAsync(Loss model, string root, IList <IFormFile> files)
        {
            var getAssets = await _LossAssetSrv.SaveRange(root, model.UserId, files);

            if (!getAssets.IsSuccessful)
            {
                return new Response <Loss> {
                           Message = getAssets.Message
                }
            }
            ;
            model.LossAssets = getAssets.Result;
            await _appUow.LossRepo.AddAsync(model);

            var saveResult = await _appUow.ElkSaveChangesAsync();

            if (!saveResult.IsSuccessful)
            {
                _LossAssetSrv.DeleteRange(getAssets.Result);
            }
            return(new Response <Loss> {
                Result = model, IsSuccessful = saveResult.IsSuccessful, Message = saveResult.Message
            });
        }
Beispiel #9
0
        public async Task <IResponse <User> > AddAsync(User model)
        {
            model.UserId   = Guid.NewGuid();
            model.Password = HashGenerator.Hash(model.Password);
            await _userRepo.AddAsync(model);

            var saveResult = await _appUow.ElkSaveChangesAsync();

            return(new Response <User> {
                Result = model, IsSuccessful = saveResult.IsSuccessful, Message = saveResult.Message
            });
        }
Beispiel #10
0
        public async Task <IResponse <bool> > DeleteAsync(int id)
        {
            var store = await _storeRepo.FindAsync(id);

            if (store == null)
            {
                return new Response <bool> {
                           Message = ServiceMessage.RecordNotExist
                }
            }
            ;
            _storeRepo.Delete(store);
            var saveResult = await _appUow.ElkSaveChangesAsync();

            return(new Response <bool>
            {
                Message = saveResult.Message,
                Result = saveResult.IsSuccessful,
                IsSuccessful = saveResult.IsSuccessful,
            });
        }
Beispiel #11
0
        public async Task <IResponse <Product> > AddAsync(ProductAddModel model)
        {
            var product = new Product().CopyFrom(model);

            if (model.TagIds != null && model.TagIds.Any())
            {
                product.ProductTags = new List <ProductTag>(model.TagIds.Select(x => new ProductTag {
                    TagId = x
                }));
            }
            if (model.Files != null && model.Files.Count != 0)
            {
                var getAssets = await _productAssetService.SaveRange(model);

                if (!getAssets.IsSuccessful)
                {
                    return new Response <Product> {
                               Message = getAssets.Message
                    }
                }
                ;
                product.ProductAssets = getAssets.Result;
                await _productRepo.AddAsync(product);

                var add = await _appUow.ElkSaveChangesAsync();

                if (!add.IsSuccessful)
                {
                    _productAssetService.DeleteRange(getAssets.Result);
                }
                return(new Response <Product> {
                    Result = product, IsSuccessful = add.IsSuccessful, Message = add.Message
                });
            }
            else
            {
                await _productRepo.AddAsync(product);

                var add = await _appUow.ElkSaveChangesAsync();

                return(new Response <Product> {
                    Result = product, IsSuccessful = add.IsSuccessful, Message = add.Message
                });
            }
        }
Beispiel #12
0
        public async Task <IResponse <Relative> > AddAsync(Relative model)
        {
            using var bt = _appUow.Database.BeginTransaction();
            await _appUow.RelativeRepo.AddAsync(model);

            var addRelativeResult = await _appUow.ElkSaveChangesAsync();

            if (!addRelativeResult.IsSuccessful)
            {
                return new Response <Relative> {
                           Message = addRelativeResult.Message
                }
            }
            ;
            #region Save Attachments
            if (model.RelativeAttachmentIds != null && model.RelativeAttachmentIds.Count > 0)
            {
                var attachments = _appUow.RelativeAttachmentRepo.Get(conditions: x => model.RelativeAttachmentIds.Contains(x.RelativeAttachmentId), orderBy: o => o.OrderBy(x => x.RelativeAttachmentId));

                if (attachments != null)
                {
                    foreach (var attachment in attachments)
                    {
                        attachment.RelativeId = model.RelativeId;
                        _appUow.RelativeAttachmentRepo.Update(attachment);
                    }
                }
                var updateAttchResult = await _appUow.ElkSaveChangesAsync();

                if (!updateAttchResult.IsSuccessful)
                {
                    bt.Rollback();
                    return(new Response <Relative> {
                        Message = updateAttchResult.Message
                    });
                }
            }
            #endregion
            bt.Commit();
            return(new Response <Relative> {
                IsSuccessful = true
            });
        }
Beispiel #13
0
        public async Task <IResponse <(Order Order, bool IsChanged)> > Add(OrderDTO model)
        {
            var chkResult = await _productSrv.CheckChanges(model.Items);

            var productId = chkResult.Items.Where(x => x.Count != 0).First().Id;
            var store     = await _appUow.ProductRepo.FirstOrDefaultAsync(x => new { x.StoreId, x.Store.AddressId }, x => x.ProductId == productId);

            if (store == null)
            {
                return new Response <(Order, bool)> {
                           Message = ServiceMessage.RecordNotExist
                }
            }
            ;
            var address = await _appUow.AddressRepo.FindAsync(store.AddressId);

            if (address == null)
            {
                await _appUow.AddressRepo.FindAsync(store.AddressId);
            }
            var getDeliveryCost = await _deliverySrv.GetDeliveryCost(model.DeliveryId, store.StoreId, new LocationDTO { Lat = model.Address.Lat, Lng = model.Address.Lng });

            if (!getDeliveryCost.IsSuccessful)
            {
                return new Response <(Order, bool)> {
                           Message = getDeliveryCost.Message
                }
            }
            ;
            var orderDetails = chkResult.Items.Where(x => x.Count != 0).Select(i => new OrderDetail
            {
                ProductId       = i.Id,
                Count           = i.Count,
                Price           = i.Price,
                TotalPrice      = i.RealPrice * i.Count,
                DiscountPrice   = i.DiscountPrice,
                DiscountPercent = i.Discount
            }).ToList();
            var order = new Order
            {
                StoreId    = store.StoreId,
                TotalPrice = orderDetails.Sum(x => x.Price * x.Count),
                TotalPriceAfterDiscount = orderDetails.Sum(x => x.TotalPrice) + getDeliveryCost.Result,
                UserId             = model.UserToken,
                DiscountPrice      = orderDetails.Sum(x => x.DiscountPrice),
                OrderStatus        = OrderStatus.WaitForPayment,
                DeliveryProviderId = model.DeliveryId,
                OrderComment       = model.Description,
                UserComment        = new UserComment {
                    Reciever = model.Reciever, RecieverMobileNumber = model.RecieverMobileNumber
                }.SerializeToJson(),
                ToAddressId = model.Address.Id ?? 0,
                ToAddress   = model.Address.Id == null ? new Address
                {
                    UserId         = model.UserToken,
                    AddressType    = AddressType.Home,
                    Latitude       = model.Address.Lat,
                    Longitude      = model.Address.Lng,
                    AddressDetails = model.Address.Address
                } : null,
                FromAddressId = store.AddressId ?? 0,
                OrderDetails  = orderDetails
            };
            await _orderRepo.AddAsync(order);

            var addOrder = await _appUow.ElkSaveChangesAsync();

            if (!addOrder.IsSuccessful)
            {
                return new Response <(Order, bool)> {
                           Message = addOrder.Message
                }
            }
            ;
            return(new Response <(Order, bool)>
            {
                IsSuccessful = true,
                Result = (order, chkResult.Changed)
            });
        }