// GET: Customer/Create
        public ActionResult Create()
        {
            CustomerViewModel data = new CustomerViewModel()
            {
                CustRef = util.GenerateCusRef()
            };

            ViewBag.cities = util.getCities();
            return(View(data));
        }
Example #2
0
        public StoreViewModel GetDetail(int id)
        {
            var result = context.Stores.Select(x => new StoreViewModel()
            {
                store_id        = x.store_id,
                City            = x.City,
                CityName        = util.getCities().FirstOrDefault(v => v.id == x.City).city,
                Date            = x.Date,
                Lat             = x.Lat,
                Lng             = x.Lng,
                Ref_No          = x.Ref_No,
                StoreName       = x.StoreName + '#' + x.Ref_No,
                SupportNo       = x.SupportNo,
                CompleteAddress = x.Address
            }).FirstOrDefault(x => x.store_id == id);

            return(result);
        }
Example #3
0
        public async Task <IActionResult> Profile()
        {
            var user = await Usermanager.GetUserAsync(User);

            if (user != null)
            {
                RegisterEmployeeViewModel r = new RegisterEmployeeViewModel()
                {
                    id           = user.Id,
                    FullName     = user.FullName,
                    Email        = user.Email,
                    City         = util.getCities().FirstOrDefault(x => x.id == user.City).city,
                    PhoneNumber  = user.PhoneNumber,
                    Photopath    = user.Photopath,
                    StreetAdress = user.StreetAdress,
                };
                if (await Usermanager.IsInRoleAsync(user, "Super Admin") || await Usermanager.IsInRoleAsync(user, "Admin"))
                {
                    var userClaims = await Usermanager.GetClaimsAsync(user);

                    var userRoles = await Usermanager.GetRolesAsync(user);

                    if (user.store_id != null)
                    {
                        r.StoreName = util.GetAllStores().FirstOrDefault(x => x.store_id == user.store_id).StoreName;
                    }
                    r.addedBy = user.addedBy;
                    foreach (var claim in userClaims)
                    {
                        UserClaim u = new UserClaim()
                        {
                            ClaimType  = claim.Type,
                            ClaimValue = claim.Value
                        };
                        r.Claims.Add(u);
                    }
                    foreach (var role in userRoles)
                    {
                        UserRoles ro = new UserRoles()
                        {
                            RoleName = role
                        };
                        r.Roles.Add(ro);
                    }
                }
                return(View(r));
            }
            else
            {
                RedirectToAction("Login");
            }
            return(View());
        }
        public IActionResult AddEmployee()
        {
            RegisterEmployeeViewModel r = new RegisterEmployeeViewModel();

            foreach (var role in Rolemanager.Roles)
            {
                if (User.IsInRole("Super Admin") || User.IsInRole("Admin") && role.Name != "Admin" && role.Name != "Super Admin")
                {
                    UserRoles user = new UserRoles()
                    {
                        RoleId     = role.Id,
                        RoleName   = role.Name,
                        isSelected = false
                    };
                    r.Roles.Add(user);
                }
            }
            foreach (Claim claim in ClaimStore.claimstore)
            {
                UserClaim userClaim = new UserClaim()
                {
                    ClaimType  = claim.Type,
                    ClaimValue = claim.Value,
                    isSelected = false,
                };
                r.Claims.Add(userClaim);
            }

            ViewBag.cities = util.getCities();
            ViewBag.Stores = util.GetAllStores();
            return(View(r));
        }
Example #5
0
        public async Task <IActionResult> Register()
        {
            if (Signinmanager.IsSignedIn(User))
            {
                if (User.IsInRole("Super Admin") || User.IsInRole("Admin"))
                {
                    return(RedirectToAction("AddEmployee", "Administration"));
                }
                else if (User.IsInRole("Employee"))
                {
                    if (!User.HasClaim(claim => claim.Type == "Create User" && claim.Value == "true"))
                    {
                        return(Forbid());
                        //return RedirectToAction("~/Administration/AccessDenied.cshtml");
                    }
                    else
                    {
                        ViewBag.cities = util.getCities();
                        ViewBag.Stores = util.GetAllStores();
                        var LoginUser = await Usermanager.GetUserAsync(User);

                        RegisterViewModel r = new RegisterViewModel();
                        if (LoginUser.store_id != null)
                        {
                            r.store_id = LoginUser.store_id;
                        }
                        return(View(r));
                    }
                }
                else
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }


            ViewBag.cities = util.getCities();
            ViewBag.Stores = util.GetAllStores();
            return(View());
        }
Example #6
0
        public int addCustomer(CustomerViewModel c)
        {
            Customer model = new Customer()
            {
                cus_name  = c.cus_name,
                cus_phone = c.cus_phone,
                CustRef   = c.CustRef
            };

            if (c.Address != null)
            {
                model.Address = new Address()
                {
                    City          = util.getCities().FirstOrDefault(p => p.id == c.Address.cityId).city,
                    Country       = c.Address.Country,
                    State         = c.Address.State,
                    StreetAddress = c.Address.StreetAddress
                };
            }
            context.Customer.Add(model);
            context.SaveChanges();
            return(model.cus_id);
        }
Example #7
0
 public ActionResult Create()
 {
     ViewBag.cities = util.getCities();
     return(View());
 }
        public async Task <List <Tuple <int, bool> > > addOrder(OrderViewModel c, IUrlHelper Url)
        {
            List <Tuple <int, bool> > quantityCheck = util.checkingquantity(c.Products, c.store_id);

            if (quantityCheck.Any(x => x.Item2 == false))
            {
                return(quantityCheck);
            }
            if (c.CustRef > 0 && Convert.ToString(c.CustRef) != String.Empty)
            {
                var result = context.Customer.Select(x => new { x.cus_id, x.CustRef }).FirstOrDefault(x => x.CustRef == c.CustRef);
                if (result != null)
                {
                    c.cus_id = result.cus_id;
                }
                else
                {
                    Customer cus = new Customer()
                    {
                        cus_name  = c.cus_name,
                        cus_phone = c.cus_phone,
                        CustRef   = c.CustRef,
                    };
                    if (c.Address != null)
                    {
                        cus.Address = new Address()
                        {
                            City          = util.getCities().FirstOrDefault(x => x.id == c.CityId).city,
                            StreetAddress = c.Address.StreetAddress
                        };
                    }
                    context.Customer.Add(cus);
                    context.SaveChanges();
                    c.cus_id = cus.cus_id;
                }
            }

            var   prices = util.Price(c.Products.Select(x => x.modelId).ToArray());
            Order model  = new Order()
            {
                Date          = DateTime.Now,
                store_id      = c.store_id,
                cus_id        = c.cus_id,
                status        = Status.Pending,
                PaymentMethod = c.Method,
                Products      = c.Products.Select(x => new Model.Order.Product()
                {
                    //Phoneid = x.Phoneid,
                    modelId  = x.modelId,
                    Quantity = x.Quantity,
                    price    = prices.FirstOrDefault(p => p.Item1 == x.modelId).Item2 *x.Quantity,
                }).ToList()
            };

            if (c.TakenBy != null)
            {
                model.TakenBy = c.TakenBy;
            }
            if (c.Method == PaymentMethods.Stripe)
            {
                if (c.stripeToken == null)
                {
                    return(new List <Tuple <int, bool> >()
                    {
                        new Tuple <int, bool>(-2, false)
                    });
                }
                double a = model.Products.Sum(x => x.price) * 0.63;
                //double per = 2.9 / 100 * a;
                var Options = new ChargeCreateOptions
                {
                    Amount      = Convert.ToInt32(a),
                    Currency    = "usd",
                    Description = "Customer Ref: " + c.CustRef,
                    Source      = c.stripeToken
                };
                var    service = new ChargeService();
                Charge charge  = service.Create(Options);
                if (charge.BalanceTransactionId == null || charge.Status.ToLower() != "succeeded")
                {
                    return(new List <Tuple <int, bool> >()
                    {
                        new Tuple <int, bool>(-2, false)
                    });
                }
                model.Charges = new List <OrderCharges>()
                {
                    new OrderCharges()
                    {
                        ChargeId = charge.Id,
                        priority = 1,
                    }
                };
            }


            context.Order.Add(model);
            context.SaveChanges();


            if (c.orderStatus == Status.Completed)
            {
                bool res = UpdateStatus(protector.Protect(model.order_id.ToString()), Status.Completed, c.TakenBy);
                if (!res)
                {
                    return new List <Tuple <int, bool> >()
                           {
                               new Tuple <int, bool>(-1, false)
                           }
                }
                ;
            }



            string StoreName = util.GetAllStores().FirstOrDefault(x => x.store_id == c.store_id).StoreName;

            c.StoreName = StoreName;
            var users = Usermanager.Users.Where(x => x.store_id == c.store_id).ToList();

            NotificationsViewModel n = new NotificationsViewModel();

            n.heading = "Order #" + model.order_id;
            n.Text    = "Order With Status " + c.orderStatus + " is Placed";
            n.Url     = Url.Action("Details", "Order", new { id = model.order_id });
            n.read    = false;
            n.When    = DateTime.Now;
            //await _hubContext.Clients.All.SendAsync("RecieveNotification", n);
            await _hubContext.Clients.Groups(StoreName).SendAsync("RecieveNotification", n);

            foreach (var em in users)
            {
                n.UserId = em.Id;
                await util.AddNotification(n);
            }
            context.SaveChanges();

            return(new List <Tuple <int, bool> >()
            {
                new Tuple <int, bool>(model.order_id, true)
            });;
        }
        // GET: Order/Create
        public async Task <ActionResult> Create(int?Phoneid, int?ModelId)
        {
            var user = await userManager.GetUserAsync(User);

            var Companies = util.GetAllCompany();

            ViewBag.Stores = util.GetAllStores();
            OrderViewModel data = new OrderViewModel();

            if (!(User.IsInRole("Admin") || User.IsInRole("Super Admin") || User.IsInRole("Employee")))
            {
                ViewBag.cities = util.getCities();
                data.cus_name  = user.FullName;
                data.cus_phone = user.PhoneNumber;
                data.CityId    = user.City;
                data.Address   = new Data.Model.Customer.Address()
                {
                    StreetAddress = user.StreetAdress
                };
                // data.Address.StreetAddress = user.StreetAdress;
                if (user.CusRef != null)
                {
                    data.CustRef = (int)user.CusRef;
                }
                else
                {
                    data.CustRef = util.GenerateCusRef();
                }
            }
            else
            {
                data.CustRef = util.GenerateCusRef();
                if (user.store_id != null)
                {
                    data.store_id = (int)user.store_id;
                }
            }
            if (ModelId != null)
            {
                //data.Phoneid = Companies.FirstOrDefault(x => x.Phoneid == Phoneid).Phoneid;
                // data.modelId = (int)ModelId;
            }
            ViewBag.Companies = Companies;
            return(View(data));
        }