Ejemplo n.º 1
0
        public async Task <IActionResult> ConfiermSealler(SeallerCodeConfiermModelView model)
        {
            var user = await userManager.FindByIdAsync(User.FindFirst("Id")?.Value);

            if (!await userManager.IsInRoleAsync(user, "Adman") && user.Block)
            {
                return(Unauthorized());
            }


            var Sealler = await userManager.FindByIdAsync(model.SeallerId);

            if (Sealler == null)
            {
                return(NotFound());
            }
            if (await userManager.IsInRoleAsync(Sealler, "Sealler"))
            {
                if (model.Confierm)
                {
                    Sealler.Confirmed = Confirmed.approved;
                }
                else
                {
                    Sealler.Confirmed = Confirmed.Reject;
                }
                await userManager.UpdateAsync(Sealler);


                var SellerName = _contect.Seallers.SingleOrDefault(i => i.id == Sealler.Id);
                var Body       = AlertNotifiction.ReadeFile("wwwroot//Emailfile//conformseller.html")
                                 .Replace("#name#", SellerName.projectAName);
                AlertNotifiction.SendEmail(user.Email, " Conform Account", _SmtpSettings, Body);


//AlertNotifiction.SendEmail(Sealler.Email, " Conform Account", _SmtpSettings, $"Dear  {Sealler.UserName }  <br> Acount is  " + Sealler.Confirmed.ToString());

                return(Ok(new { Sealler.Id }));
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 2
0
        // [Obsolete]
        public async Task <IActionResult> GetConformUser(string Email)
        {
            var user = await userManager.FindByNameAsync(Email);

            if (await userManager.IsInRoleAsync(user, "User") && user.Confirmed != Confirmed.block && !user.Block)
            {
                var Code     = new Random().Next(1234, 9999);
                var UserCode = _contect.UserCodeConfierm.SingleOrDefault(i => i.UserId == user.Id && i.Type == Codetype.PasswordUser);
                if (UserCode != null)
                {
                    UserCode.Code       = Code.ToString();
                    UserCode.ExperdDate = DateTime.Now.AddMinutes(10);
                    UserCode.Type       = Codetype.PasswordUser;
                }
                else
                {
                    var UserCodeConfierm = new UserCodeConfierm()
                    {
                        ExperdDate = DateTime.Now.AddMinutes(10),
                        UserId     = user.Id,
                        Code       = Code.ToString(),
                        Type       = Codetype.PasswordUser
                    };
                    _contect.UserCodeConfierm.Add(UserCodeConfierm);
                }


                _contect.SaveChanges();
                var Use  = _contect.Users.SingleOrDefault(i => i.id == user.Id);
                var Body = AlertNotifiction.ReadeFile("wwwroot//Emailfile//conformEmile.html")
                           .Replace("#name#", Use.AName).Replace("#code#", Code.ToString());
                AlertNotifiction.SendEmail(user.Email, " Conform Account", _SmtpSettings, Body);

                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 3
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)); }
        }
Ejemplo n.º 4
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"));
            }
        }
Ejemplo n.º 5
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());
            }
        }
Ejemplo n.º 6
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());
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> RegisterUser(UserModelview model)
        {
            if (ModelState.IsValid)
            {
                var User = new UserIdentity()
                {
                    UserName    = model.Email,
                    PhoneNumber = model.Phon,
                    Email       = model.Email,
                    Confirmed   = Confirmed.non,
                    Block       = false
                };

                try
                {
                    var result = await userManager.CreateAsync(User, model.Password);

                    if (result.Succeeded)
                    {
                        var user = new User()
                        {
                            id    = User.Id,
                            Name  = model.Name,
                            AName = model.AName,
                            Hdate = DateTime.Now,
                        };

                        if (!await roleManager.RoleExistsAsync("User"))
                        {
                            await roleManager.CreateAsync(new IdentityRole("User"));
                        }
                        await userManager.AddToRoleAsync(User, "User");

                        _contect.Users.Add(user);
                        _contect.SaveChanges();

                        //get Token :)
                        var claim = new[]
                        {
                            new Claim("Id", User.Id),

                            new Claim("Rolas", userManager.GetRolesAsync(User).Result.FirstOrDefault())
                        };
                        var signinKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:SigningKey"]));

                        int expiryInMinutes = Convert.ToInt32(_configuration["Jwt:ExpiryInHouer"]);

                        var token = new JwtSecurityToken(
                            claims: claim,
                            issuer: _configuration["Jwt:Site"],
                            audience: _configuration["Jwt:Site"],
                            expires: DateTime.UtcNow.AddHours(expiryInMinutes),
                            signingCredentials: new SigningCredentials(signinKey, SecurityAlgorithms.HmacSha256)
                            );

                        /// code conform
                        var Code             = new Random().Next(1234, 9999);
                        var UserCodeConfierm = new UserCodeConfierm()
                        {
                            ExperdDate = DateTime.Now.AddMinutes(10),
                            UserId     = user.id,
                            Code       = Code.ToString(),
                            Type       = Codetype.PasswordUser
                        };
                        _contect.UserCodeConfierm.Add(UserCodeConfierm);
                        _contect.SaveChanges();

                        var Body = AlertNotifiction.ReadeFile("wwwroot//Emailfile//conformEmile.html")
                                   .Replace("#name#", user.AName).Replace("#code#", Code.ToString());
                        AlertNotifiction.SendEmail(user.UserIdentity.Email, " Conform Account", _SmtpSettings, Body);

                        return(Ok(new
                        {
                            token = new JwtSecurityTokenHandler().WriteToken(token),
                            expiration = token.ValidTo,
                            user.id,
                            user.Name,
                            user.AName,
                            user.UserIdentity.Email,
                            user.UserIdentity.PhoneNumber,
                            Roles = userManager.GetRolesAsync(User).Result.FirstOrDefault()
                        }));
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(new IdentityError()
                    {
                        Description = e.Message.ToString()
                    }));
                }
            }
            else
            {
                return(BadRequest());
            }
        }