Пример #1
0
        public async Task <IActionResult> Approved(orderstateModeview model)
        {
            try
            {
                var user = await userManager.FindByIdAsync(User.FindFirst("Id")?.Value);

                if (user == null)
                {
                    return(Unauthorized());
                }
                if (await userManager.IsInRoleAsync(user, "Sealler") && user?.Confirmed == Confirmed.approved && !user.Block)
                {
                    var order = _contect.Orders.Include(i => i.User.UserIdentity).SingleOrDefault(i => i.Id == model.OrderId && i.SeallerId == user.Id);
                    if (order == null)
                    {
                        return(NotFound());
                    }
                    //get UserDevice Key
                    var connectionFierbaseId = _contect.NotificationTokens.Where(i => i.UserId == order.UserId).Select(i => i.connectionFierbaseId).ToList();



                    if (order.Cancel)
                    {
                        return(BadRequest($"order Cancel from User"));
                    }
                    if (model.orderStatus == orderStatus.Approved)
                    {
                        if (order.orderStatus == orderStatus.Reject || order.orderStatus == orderStatus.Ordered)
                        {
                            order.orderStatus = model.orderStatus;

                            AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, " قبول الطلب ", $"{order.ProductAName} تم قبول طلب للمنتج ");
                        }
                        else
                        {
                            throw new Exception($"order is {order.orderStatus} ");
                        }
                    }
                    else if (model.orderStatus == orderStatus.Reject)
                    {
                        if (order.orderStatus == orderStatus.Ordered || order.orderStatus == orderStatus.Approved)
                        {
                            order.orderStatus = model.orderStatus;
                            AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, " رفض الطلب ", $"{order.ProductAName} تم رفض طلب للمنتج ");
                        }
                        else
                        {
                            throw new Exception($"order is {order.orderStatus} ");
                        }
                    }
                    else if (model.orderStatus == orderStatus.Finshed)
                    {
                        if (order.orderStatus == orderStatus.Approved)
                        {
                            order.orderStatus = model.orderStatus;
                            AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, "  الطلب ", $"{order.ProductAName} تم قبول طلب للمنتج ");
                        }
                        else
                        {
                            throw new Exception($"order is {order.orderStatus} ");
                        }
                    }
                    else if (model.orderStatus == orderStatus.delivery)
                    {
                        if (order.orderStatus == orderStatus.Finshed || order.orderStatus == orderStatus.Approved)
                        {
                            order.orderStatus = model.orderStatus;
                            AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, " طلب  ", $"{order.ProductAName} خلال 24 ساعة  طلبك في الوصول اليك  ");



                            var Body = AlertNotifiction.ReadeFile("wwwroot//Emailfile//OrderDelvery.html")
                                       .Replace("#name#", order.User.Name)
                                       .Replace("#oductName#", order.ProductAName)
                            ;
                            AlertNotifiction.SendEmail(order.User.UserIdentity.Email, "orderStatus  delivery", _SmtpSettings, Body);
                            //    #oductName# string body = $"Hi  \n  the Receipt Code of   Order Number# :{order.Id.ToString()} \n  Receipt Code :  {ReceiptCode.Code.ToString()} \n ExperDate  : { ReceiptCode.ExperDate.ToString()}";
                            // AlertNotifiction.SendEmail(order.User.UserIdentity.Email, "orderStatus  delivery", _SmtpSettings, $"Hi {order.User.Name} <br>   order is   delivery <br> order Number #{order.Id}  thx :)  ");
                        }

                        else
                        {
                            throw new Exception($"order is {order.orderStatus} ");
                        }
                    }
                    else
                    {
                        throw new Exception($"order is {order.orderStatus} ");
                    }

                    _contect.SaveChanges();


                    return(Ok(
                               new
                    {
                        order.Id,
                        order.ProductName,
                        order.ProductAName,
                        order.Productprice,

                        order.description,

                        // ProductForm = order.Form.Select(i => new { i.id, i.AKey, i.Key, i.value }).ToList(),
                        order.CodeColor,
                        order.ANameColor,
                        order.NameColor,
                        order.orderStatus,
                        order.Cuantity,
                        order.ProductpriceTotal,
                        order.Date,
                        order.Timespent,
                        order.TimespentEnd,
                        order.UserAddress,
                        order.otherPhoneNo,
                    }));
                }
                else if (await userManager.IsInRoleAsync(user, "Adman") && user?.Confirmed == Confirmed.approved && !user.Block)
                {
                    var order = _contect.Orders.Include(i => i.User.UserIdentity).SingleOrDefault(i => i.Id == model.OrderId);
                    if (order == null)
                    {
                        return(NotFound());
                    }

                    if (model.orderStatus == orderStatus.Approved)
                    {
                        if (order.orderStatus == orderStatus.Reject || order.orderStatus == orderStatus.Ordered)
                        {
                            order.orderStatus = model.orderStatus;
                        }
                        else
                        {
                            throw new Exception($"order is {order.orderStatus} ");
                        }
                    }
                    else if (model.orderStatus == orderStatus.Reject)
                    {
                        if (order.orderStatus == orderStatus.Ordered || order.orderStatus == orderStatus.Approved)
                        {
                            order.orderStatus = model.orderStatus;
                        }
                        else
                        {
                            throw new Exception($"order is {order.orderStatus} ");
                        }
                    }
                    else if (model.orderStatus == orderStatus.Finshed)
                    {
                        if (order.orderStatus == orderStatus.Approved)
                        {
                            order.orderStatus = model.orderStatus;
                        }
                        else
                        {
                            throw new Exception($"order is {order.orderStatus} ");
                        }
                    }
                    else if (model.orderStatus == orderStatus.delivery)
                    {
                        if (order.orderStatus == orderStatus.Finshed || order.orderStatus == orderStatus.Approved)
                        {
                            order.orderStatus = model.orderStatus;
                        }
                        else
                        {
                            throw new Exception($"order is {order.orderStatus} ");
                        }
                    }
                    else if (model.orderStatus == orderStatus.Receipt)
                    {
                        if (order.orderStatus == orderStatus.Finshed || order.orderStatus == orderStatus.delivery)
                        {
                            order.orderStatus = model.orderStatus;
                            try
                            {
                                //  string body = $"Hi  \n  the Receipt Code of   Order Number# :{order.Id.ToString()} \n  Receipt Code :  {ReceiptCode.Code.ToString()} \n ExperDate  : { ReceiptCode.ExperDate.ToString()}";
                                AlertNotifiction.SendEmail(order.User.UserIdentity.Email, "orderStatus  Receipt", _SmtpSettings, "Hi    the Receipt Code of Receipt Code :  ");
                            }
                            catch (Exception e) { }
                        }

                        else
                        {
                            throw new Exception($"order is {order.orderStatus} ");
                        }
                    }
                    else
                    {
                        throw new Exception($"order is {order.orderStatus} ");
                    }

                    _contect.SaveChanges();

                    return(Ok(
                               new
                    {
                        order.Id,
                        order.ProductName,
                        order.ProductAName,
                        order.Productprice,

                        order.description,

                        // ProductForm = order.Form.Select(i => new { i.id, i.AKey, i.Key, i.value }).ToList(),
                        order.CodeColor,
                        order.ANameColor,
                        order.NameColor,
                        order.orderStatus,
                        order.Cuantity,
                        order.ProductpriceTotal,
                        order.Date,
                        order.Timespent,
                        order.TimespentEnd,
                        order.UserAddress,
                        order.otherPhoneNo,
                    }));
                }
                else
                {
                    return(Unauthorized());
                }
            }
            catch (Exception e) { return(BadRequest(e.Message)); }
        }
Пример #2
0
        public async Task <IActionResult> Receipt(int OrderId)
        {
            var user = await userManager.FindByIdAsync(User.FindFirst("Id")?.Value);

            if (user == null)
            {
                return(Unauthorized());
            }
            if (await userManager.IsInRoleAsync(user, "User") && user?.Confirmed == Confirmed.approved && !user.Block)
            {
                var order = _contect.Orders.SingleOrDefault(i => i.Id == OrderId && user.Id == i.UserId);
                if (order == null)
                {
                    return(NotFound());
                }
                else if (order.Cancel)
                {
                    return(BadRequest($"this order Cancel "));
                }

                else
                {
                    if (order.orderStatus == orderStatus.Receipt || order.orderStatus == orderStatus.delivery)
                    {
                        return(BadRequest($"this Order Is {order.orderStatus} "));
                    }
                    else
                    {
                        order.Cancel = true;
                        var Product = _contect.products.SingleOrDefault(i => i.Id == order.ProductId);
                        if (Product != null)
                        {
                            if (Product.Stock)
                            {
                                Product.StockCount += order.Cuantity;
                            }
                        }


                        _contect.SaveChanges();

                        var connectionFierbaseId = _contect.NotificationTokens.Where(i => i.UserId == order.UserId || i.UserId == order.SeallerId)
                                                   .Select(i => i.connectionFierbaseId).ToList();
                        AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, "    الغاء الطلب", $"{order.ProductAName} تم الغاء الطلب  للمنتج ");


                        return(Ok(
                                   new
                        {
                            order.Id,
                            order.ProductName,
                            order.ProductAName,
                            order.Productprice,

                            order.description,
                            order.Cancel,

                            // ProductForm = order.Form?.Select(i => new { i.id, i.AKey, i.Key, i.value }).ToList(),
                            order.CodeColor,
                            order.ANameColor,
                            order.NameColor,
                            order.orderStatus,
                            order.Cuantity,
                            order.ProductpriceTotal,
                            order.Date,
                            order.Timespent,
                            order.TimespentEnd,
                            order.UserAddress,
                            order.otherPhoneNo,
                            order.ReceiptDate
                        }));
                    }
                }
            }
            else
            {
                return(Unauthorized());
            }
        }
Пример #3
0
        public async Task <IActionResult> PostOrders(OrderModeView model)
        {
            var user = await userManager.FindByIdAsync(User.FindFirst("Id")?.Value);

            if (user == null)
            {
                return(Unauthorized());
            }
            if (await userManager.IsInRoleAsync(user, "User") && user?.Confirmed == Confirmed.approved && !user.Block)
            {
                var Prodect = _contect.products
                              .Include(i => i.Colors)
                              .Include(i => i.Form)
                              //.Include(i=>i.Form)
                              .Include(i => i.sealler)
                              .Include(i => i.Img)
                              .Include(i => i.sealler.UserIdentity)

                              .SingleOrDefault(i => i.Id == model.ProductId && i.Delete == false && i.sealler.UserIdentity.Block == false);

                var prodectColore = Prodect.Colors.SingleOrDefault(i => i.Id == model.ColorId);

                if (Prodect == null)
                {
                    return(NotFound());
                }
                if (Prodect.sealler.UserIdentity.Block == true)
                {
                    return(NotFound("this seller is Block"));
                }
                if (Prodect.Stock && Prodect.StockCount - model.Cuantity < 0)
                {
                    return(NotFound("Prodect out  Stock"));
                }
                var Order = new Order();

                Order.Date         = DateTime.Now;
                Order.UserId       = user.Id;
                Order.UserAddress  = model.UserAddress;
                Order.otherPhoneNo = model.otherPhoneNo;
                Order.description  = model.description;
                Order.ProductId    = Prodect.Id;
                Order.ProductAName = Prodect.AName;
                Order.ProductName  = Prodect.Name;
                Order.Productprice = Prodect.price;
                Order.Timespent    = Prodect.Timespent;
                Order.Cuantity     = model.Cuantity;
                Order.SeallerId    = Prodect.SeallerId;
                var fromprodect = _contect.productFormsetup.Where(i => i.ProductId == Prodect.Id).Include(i => i.Form).ToList();
                Order.Form = new List <OrderForm>();
                foreach (var item in fromprodect)
                {
                    Order.Form.Add(new OrderForm()
                    {
                        Key = item.Form.Name, AKey = item.Form.AName, value = item.value
                    });
                }


                Order.ProductStock = Prodect.Stock;
                if (Prodect.Stock)
                {
                    Prodect.StockCount -= model.Cuantity;
                    Order.orderStatus   = orderStatus.Approved;
                }
                else
                {
                    Order.orderStatus = orderStatus.Ordered;
                }

                if (prodectColore != null)
                {
                    Order.CodeColor  = prodectColore.Code;
                    Order.NameColor  = prodectColore.Color;
                    Order.ANameColor = prodectColore.AColor;
                }



                Order.SeallerId = Prodect.SeallerId;

                _contect.Orders.Add(Order);
                _contect.SaveChanges();
                var connectionFierbaseId = _contect.NotificationTokens.Where(i => i.UserId == Order.SeallerId)
                                           .Select(i => i.connectionFierbaseId).ToList();
                AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, "لديك طلب جديد ", $"{Order.ProductAName} تم  طلب للمنتج ");



                return(Ok(
                           new
                {
                    Order.Id,
                    Order.ProductName,
                    Order.ProductAName,
                    Order.Productprice,

                    Order.description,
                    ProdectImg = Prodect.Img.Select(i => imgProdectPath + i.img).ToList(),
                    ProductForm = Order.Form?.Select(i => new { i.id, i.AKey, i.Key, i.value }).ToList(),
                    Order.CodeColor,
                    Order.ANameColor,
                    Order.NameColor,
                    Order.orderStatus,
                    Order.Cuantity,
                    Order.ProductpriceTotal,
                    Order.Date,
                    Order.Timespent,
                    Order.TimespentEnd,
                    Order.UserAddress,
                    Order.otherPhoneNo,
                }));
            }
            else
            {
                return(Unauthorized("Token not User"));
            }
        }
Пример #4
0
        public async Task <IActionResult> Receipt(ReceiptModelView model)
        {
            var order       = new Order();
            var ReceiptCode = new ReceiptCode();
            var user        = await userManager.FindByIdAsync(User.FindFirst("Id")?.Value);

            if (user == null)
            {
                return(Unauthorized());
            }
            if (await userManager.IsInRoleAsync(user, "Sealler") && user?.Confirmed == Confirmed.approved && !user.Block)
            {
                order = _contect.Orders.SingleOrDefault(i => i.Id == model.OrderId);
                if (order == null)
                {
                    return(NotFound());
                }
                ReceiptCode = _contect.ReceiptCode.SingleOrDefault(i => i.OrderId == order.Id && i.UserId == order.UserId && i.Code.ToString() == model.Code && i.ExperDate >= DateTime.Now);
                if (ReceiptCode == null)
                {
                    return(NotFound());
                }
                else
                {
                    ReceiptCode.SeallerId   = user.Id;
                    ReceiptCode.ReceiptDate = DateTime.Now;
                    order.orderStatus       = orderStatus.Receipt;
                    order.ReceiptDate       = ReceiptCode.ReceiptDate;
                    _contect.SaveChanges();
                    var connectionFierbaseId = _contect.NotificationTokens.Where(i => i.UserId == order.UserId || i.UserId == order.SeallerId)
                                               .Select(i => i.connectionFierbaseId).ToList();
                    AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, "  الطلب استلام الطلب", $"{order.ProductAName} تم استلام الطلب طلب للمنتج ");
                }



                return(Ok(
                           new
                {
                    order.Id,
                    order.ProductName,
                    order.ProductAName,
                    order.Productprice,

                    order.description,

                    // ProductForm = order.Form?.Select(i => new { i.id, i.AKey, i.Key, i.value }).ToList(),
                    order.CodeColor,
                    order.ANameColor,
                    order.NameColor,
                    order.orderStatus,
                    order.Cuantity,
                    order.ProductpriceTotal,
                    order.Date,
                    order.Timespent,
                    order.TimespentEnd,
                    order.UserAddress,
                    order.otherPhoneNo,
                    order.ReceiptDate,
                }));
            }
            else
            {
                return(Unauthorized());
            }
        }