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));
        }
Exemplo n.º 2
0
        public override async Task OnConnectedAsync()
        {
            //string loggedInAdminId = HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            var user = UserManager.Users.FirstOrDefault(x => x.Id == Context.UserIdentifier);

            if (user.store_id != null)
            {
                string StoreName = util.GetAllStores().FirstOrDefault(x => x.store_id == user.store_id).StoreName;
                await Groups.AddToGroupAsync(Context.ConnectionId, StoreName);
            }
            await base.OnConnectedAsync();
        }
Exemplo n.º 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());
        }
Exemplo n.º 4
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());
        }
        public async Task <ActionResult> Create(int?store_id, int?modelId, int?PhoneId)
        {
            ViewBag.Stores    = util.GetAllStores();
            ViewBag.Companies = util.GetAllCompany();
            if (store_id != null)
            {
                PurchasingViewModel p = new PurchasingViewModel();
                if (modelId != null && PhoneId != null)
                {
                    p.modelId = (int)modelId;
                    p.Phoneid = (int)PhoneId;
                }
                p.store_id = (int)store_id;
                return(View(p));
            }
            else
            {
                var user = await userManager.GetUserAsync(User);

                if (user.store_id != null)
                {
                    PurchasingViewModel p = new PurchasingViewModel();
                    p.store_id = (int)user.store_id;
                    return(View(p));
                }
            }

            return(View());
        }
Exemplo n.º 6
0
        public async Task <int> addPurchasing(PurchasingViewModel c, IUrlHelper Url)
        {
            bool res = false;
            // var price = context.BrandModel.Select(x => new { x.Price, x.modelId }).FirstOrDefault(x => x.modelId == c.modelId);
            Purchasing model = new Purchasing()
            {
                Date      = c.Date,
                Quantity  = c.Quantity,
                Amount    = c.Amount,
                modelId   = c.modelId,
                vendor_id = c.vendor_id,
                store_id  = c.store_id,
                takenBy   = c.takenBy,
            };

            context.Purchasings.Add(model);
            context.SaveChanges();
            res = util.updateSingleQuantity(c.modelId, c.Quantity, c.store_id, "Add");
            if (res == false)
            {
                return(0);
            }
            string StoreName = util.GetAllStores().FirstOrDefault(x => x.store_id == c.store_id).StoreName;
            var    users     = UserManager.Users.Where(x => x.store_id == c.store_id).ToList();

            NotificationsViewModel n = new NotificationsViewModel();

            n.heading = "Purchasing #" + model.purchase_id;
            n.Text    = "Items Purchased By " + c.takenBy;
            n.Url     = Url.Action("Details", "Purchasing", new { id = model.purchase_id });
            n.read    = false;
            n.When    = DateTime.Now;
            await _hubContext.Clients.Groups(StoreName).SendAsync("RecieveNotification", n);

            foreach (var em in users)
            {
                n.UserId = em.Id;
                await util.AddNotification(n);
            }
            context.SaveChanges();
            return(model.purchase_id);
        }
Exemplo n.º 7
0
        public async Task <int> addModel(ModelViewModel model)
        {
            BrandModel m = new BrandModel()
            {
                model_name       = model.model_name,
                mob_type         = model.mob_type,
                RAM              = model.RAM + " " + model.RAMCapacity,
                internal_storage = model.internal_storage + " " + model.ROMCapacity,
                Display          = model.Display,
                Battery          = model.Battery,
                Price            = model.Price,
                SimType          = model.SimType, //require end
                back_cam         = model.back_cam,
                Front_Cam        = model.Front_Cam,
                front_flash      = model.front_flash,
                FingerPrint      = model.FingerPrint,
                Networktype      = model.Networktype,
                PhoneId          = model.PhoneId,
                ProcessorName    = model.ProcessorName,
                LaunchDate       = model.LaunchDate,
                Android          = model.Android
            };

            context.BrandModel.Add(m);
            context.SaveChanges();

            string uniqueFileName = null;

            if (model.Photos != null && model.Photos.Count > 0)
            {
                // Loop thru each selected file
                foreach (IFormFile photo in model.Photos)
                {
                    // The file must be uploaded to the images folder in wwwroot
                    // To get the path of the wwwroot folder we are using the injected
                    // IHostingEnvironment service provided by ASP.NET Core
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "image");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                    // To make sure the file name is unique we are appending a new
                    // GUID value and and an underscore to the file name
                    ModelImages i = new ModelImages()
                    {
                        modelId    = m.modelId,
                        Image_Path = uniqueFileName,
                    };
                    context.Images.Add(i);


                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    // Use CopyTo() method provided by IFormFile interface to
                    // copy the file to wwwroot/images folder
                    photo.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                context.SaveChanges();
            }

            var          Stores = util.GetAllStores();
            List <Stock> stock  = new List <Stock>();

            foreach (var store in Stores)
            {
                Stock s = new Stock()
                {
                    modelId  = m.modelId,
                    Quantity = 0,
                    store_id = store.store_id
                };
                stock.Add(s);
            }
            await context.Stock.AddRangeAsync(stock);

            await context.SaveChangesAsync();

            return(m.modelId);
        }
Exemplo n.º 8
0
        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)
            });;
        }
 public IActionResult AddStockManually()
 {
     ViewBag.Companies = util.GetAllCompany();
     ViewBag.Stores    = util.GetAllStores();
     return(View());
 }
Exemplo n.º 10
0
        // 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));
        }