Exemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "BusinessId,Name,Slogan,UserId,AddressId,Phone,Banner,BannerFile,Latitude,Longitude,IsBarberShop,IsHairSalon,IsNailSalon,IsMakeUp,IsDisabled,AddressInfoHidden,AddedDate,ModifiedDate")] Business business)
        {
            if (ModelState.IsValid)
            {
                business.ModifiedDate = DateTime.Now;

                if (business.BannerFile != null)
                {
                    var    folder         = "~/Content/Banners";
                    string pic            = string.Format("{0}{1}", business.BusinessId, Path.GetExtension(business.BannerFile.FileName));
                    bool   uploadResponse = FilesHelper.UploadImage(business.BannerFile, folder, pic);
                    if (uploadResponse)
                    {
                        business.Banner = string.Format("{0}/{1}", folder, pic);
                    }
                }

                db.Entry(business).State = EntityState.Modified;

                Response response = DBHelper.SaveChanges(db);
                if (response.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, response.Message);
            }
            ViewBag.AddressId = new SelectList(ListsHelper.GetUserAddresses(business.UserId), "AddressId", "Description", business.AddressId);
            return(View(business));
        }
Exemplo n.º 2
0
        public ActionResult EditMe(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ClientList clientList = db.ClientLists.Find(id);

            if (clientList == null)
            {
                return(HttpNotFound());
            }

            User user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            bool isEmployee = UsersHelper.IsEmployeeOfCurrentBusiness(User, clientList.EmployeeId);

            if (user.UserId != clientList.Customer.UserId)
            {
                if (isEmployee)
                {
                    return(RedirectToAction("Edit"));
                }
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.ServiceId = new SelectList(ListsHelper.GetEmployeeServices(clientList.EmployeeId), "ServiceId", "Description", clientList.ServiceId);

            return(View(clientList));
        }
Exemplo n.º 3
0
        public ActionResult EditMe([Bind(Include = "ClientListId,ListStatusId,CustomerId,EmployeeId,ServiceId,Appointment,AddedByUserId,AddedDate")] ClientList clientList)
        {
            User     user     = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
            Customer customer = db.Customers.Find(clientList.CustomerId);

            if (user.UserId != customer.UserId)
            {
                ModelState.AddModelError(string.Empty, "Autorization Denied");
            }

            if (ModelState.IsValid)
            {
                clientList.ModifiedByUserId = user.UserId;
                clientList.ModifiedDate     = DateTime.Now;
                db.Entry(clientList).State  = EntityState.Modified;
                db.SaveChanges();

                if (UsersHelper.IsEmployeeOfCurrentBusiness(User, clientList.EmployeeId))
                {
                    return(RedirectToAction("Index", new { id = clientList.EmployeeId }));
                }
                return(RedirectToAction("EmployeeCustomers", new { id = clientList.EmployeeId }));
            }

            ViewBag.ServiceId   = new SelectList(ListsHelper.GetEmployeeServices(clientList.EmployeeId), "ServiceId", "Description", clientList.ServiceId);
            clientList.Customer = customer;

            return(View(clientList));
        }
Exemplo n.º 4
0
        public void CompareByIdTest()
        {
            var  comparer  = new ByIdComparer <DbFavorite>();
            bool identical = comparer.Equals(favoriteA, favoriteA);

            Assert.IsTrue(identical, "By Id compare failed");

            bool different = comparer.Equals(favoriteA, favoriteB);

            Assert.IsFalse(different);

            var listA = new List <DbFavorite> {
                favoriteA
            };
            var listB = new List <DbFavorite> {
                favoriteB
            };
            var missing = ListsHelper.GetMissingSourcesInTarget(listA, listB, comparer);

            Assert.AreEqual(1, missing[0].Id, "Missing favorite by Id wasn't found");
            var empty = ListsHelper.GetMissingSourcesInTarget(listA, new List <DbFavorite> {
                favoriteA
            }, comparer).ToList();

            Assert.AreEqual(0, empty.Count, "Favorite wasn't found in second collection");
        }
Exemplo n.º 5
0
        public ActionResult Edit([Bind(Include = "ClientListId,ListStatusId,CustomerId,EmployeeId,ServiceId,Appointment,ServiceStarted,ServiceEnded,AddedByUserId,AddedDate")] ClientList clientList)
        {
            User user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                clientList.ModifiedByUserId = user.UserId;
                clientList.ModifiedDate     = DateTime.Now;
                db.Entry(clientList).State  = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = clientList.EmployeeId }));
            }

            ////ModelState Validation
            //var s = string.Empty;
            //var n = 0;
            //foreach (var modelState in ViewData.ModelState)
            //{
            //    foreach (ModelError error in modelState.Value.Errors)
            //    {
            //        s = string.Format("{0} {1}", modelState.Key, error.ErrorMessage);
            //        n = 0;
            //    }
            //}

            bool isEmployee = UsersHelper.IsEmployeeOfCurrentBusiness(User, clientList.EmployeeId);

            clientList.Customer = db.Customers.Find(clientList.CustomerId);
            ViewBag.ServiceId   = new SelectList(ListsHelper.GetEmployeeServices(clientList.EmployeeId), "ServiceId", "Description", clientList.ServiceId);

            return(View(clientList));
        }
Exemplo n.º 6
0
        private static void UpdateGroupsMembership(IFavorite favorite, List <IGroup> newGroups)
        {
            List <IGroup> redundantGroups = ListsHelper.GetMissingSourcesInTarget(favorite.Groups, newGroups);
            List <IGroup> missingGroups   = ListsHelper.GetMissingSourcesInTarget(newGroups, favorite.Groups);

            Data.Favorites.AddIntoMissingGroups(favorite, missingGroups);
            Data.Groups.RemoveFavoritesFromGroups(new List <IFavorite> {
                favorite
            }, redundantGroups);
        }
Exemplo n.º 7
0
 public ActionResult Create([Bind(Include = "EmployeeId,ServiceId,IsDisabled")] EmployeeService employeeService)
 {
     if (ModelState.IsValid)
     {
         db.EmployeeServices.Add(employeeService);
         db.SaveChanges();
         return(RedirectToAction("Index", new { id = employeeService.EmployeeId }));
     }
     ViewBag.ServiceId = new SelectList(ListsHelper.GetServices(), "ServiceId", "Description", employeeService.ServiceId);
     return(View(employeeService));
 }
Exemplo n.º 8
0
        public ActionResult Create([Bind(Include = "ListStatusId,Description,PriorityLevelId,Active,Completed,SystemStatus,Canceled,Unconfirmed,Confirmed,Current")] ListStatus listStatus)
        {
            if (ModelState.IsValid)
            {
                db.ListStatus.Add(listStatus);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PriorityLevelId = new SelectList(ListsHelper.GetPriorityLevels(), "PriorityLevelId", "Description", listStatus.PriorityLevelId);
            return(View(listStatus));
        }
Exemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "AddressId,CountryId,UserId,Description,FullName,Address1,Address2,City,State,ZIP,IsDefault,IsDisabled,ReturnUrl")] Address address)
 {
     if (!Url.IsLocalUrl(address.ReturnUrl))
     {
         address.ReturnUrl = "~/Home/Index";
     }
     if (ModelState.IsValid)
     {
         db.Entry(address).State = EntityState.Modified;
         db.SaveChanges();
         return(Redirect(address.ReturnUrl));
     }
     ViewBag.CountryId = new SelectList(ListsHelper.GetCountries(), "CountryId", "Name", address.CountryId);
     return(View(address));
 }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "ClientListId,CustomerId,EmployeeId,ServiceId,Appointment,CustomerName")] ClientList clientList)
        {
            User user       = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
            bool isEmployee = UsersHelper.IsEmployeeOfCurrentBusiness(User, clientList.EmployeeId);

            if (!isEmployee)
            {
                return(RedirectToAction("BusinessCustomers"));
            }

            Customer customer = db.Customers.Find(clientList.CustomerId);

            if (string.IsNullOrEmpty(clientList.CustomerName))
            {
                ModelState.AddModelError("CustomerName", "The field Customer is required");
            }
            else if (customer != null)
            {
                if (isEmployee && customer.UserId == user.UserId && customer.IsAccountOwner)
                {
                    ModelState.AddModelError(string.Empty, "Same employee customer not allowed");
                }
            }
            else
            {
                ModelState.AddModelError("CustomerName", "Customer not found");
            }

            if (ModelState.IsValid)
            {
                clientList.ListStatusId     = db.ListStatus.Where(ls => ls.Confirmed == true).FirstOrDefault().ListStatusId;
                clientList.AddedByUserId    = user.UserId;
                clientList.AddedDate        = DateTime.Now;
                clientList.ModifiedByUserId = user.UserId;
                clientList.ModifiedDate     = clientList.AddedDate;

                db.ClientLists.Add(clientList);
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = clientList.EmployeeId }));
            }

            ViewBag.ServiceId      = new SelectList(ListsHelper.GetEmployeeServices(clientList.EmployeeId), "ServiceId", "Description", clientList.EmployeeId);
            ViewBag.CustomerId     = new SelectList(ListsHelper.GetCustomers(isEmployee, user.UserId), "CustomerId", "CustomerName", clientList.CustomerId);
            ViewBag.ReturnUrl      = string.Format("~/ClientLists/Create/{0}", clientList.EmployeeId);
            ViewBag.EmployeeName   = user.Name;
            ViewBag.EmployeeUserId = user.UserId;
            return(View(clientList));
        }
Exemplo n.º 11
0
        // GET: EmployeeServices/Edit/5
        public ActionResult Edit(int?eId, int?sId)
        {
            if (eId == null || sId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeService employeeService = db.EmployeeServices.Find(eId, sId);

            if (employeeService == null)
            {
                return(HttpNotFound());
            }

            ViewBag.ServiceId = new SelectList(ListsHelper.GetServices(), "ServiceId", "Description", employeeService.ServiceId);
            return(View(employeeService));
        }
Exemplo n.º 12
0
        // GET: Businesses/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Business business = db.Businesses.Find(id);

            if (business == null)
            {
                return(HttpNotFound());
            }

            ViewBag.AddressId = new SelectList(ListsHelper.GetUserAddresses(business.UserId), "AddressId", "Description", business.AddressId);
            return(View(business));
        }
Exemplo n.º 13
0
        // GET: Addresses/Create
        public ActionResult Create(string returnUrl)
        {
            if (!Url.IsLocalUrl(returnUrl))
            {
                returnUrl = "~/Home/Index";
            }

            User user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            ViewBag.CountryId = new SelectList(ListsHelper.GetCountries(), "CountryId", "Name");

            Address address = new Address {
                UserId = user.UserId, ReturnUrl = returnUrl
            };

            return(View(address));
        }
Exemplo n.º 14
0
        internal void RefreshCache()
        {
            var newlyLoaded = this.Load(this.Cached);
            var oldGroups   = this.Cached;

            var missing   = ListsHelper.GetMissingSourcesInTarget(newlyLoaded, oldGroups);
            var redundant = ListsHelper.GetMissingSourcesInTarget(oldGroups, newlyLoaded);

            this.cache.Add(missing);
            this.cache.Delete(redundant);
            this.RefreshLoaded();

            var missingToReport   = missing.Cast <IGroup>().ToList();
            var redundantToReport = redundant.Cast <IGroup>().ToList();

            this.dispatcher.ReportGroupsRecreated(missingToReport, redundantToReport);
        }
Exemplo n.º 15
0
        // GET: Addresses/Edit/5
        public ActionResult Edit(int?id, string returnUrl)
        {
            if (!Url.IsLocalUrl(returnUrl))
            {
                returnUrl = "~/Home/Index";
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Address address = db.Addresses.Find(id);

            if (address == null)
            {
                return(HttpNotFound());
            }
            address.ReturnUrl = returnUrl;
            ViewBag.CountryId = new SelectList(ListsHelper.GetCountries(), "CountryId", "Name", address.CountryId);
            return(View(address));
        }
Exemplo n.º 16
0
        // GET: EmployeeServices/Create
        public ActionResult Create(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Employee employee = db.Employees.Find(id);

            if (employee == null)
            {
                return(HttpNotFound());
            }

            ViewBag.ServiceId = new SelectList(ListsHelper.GetServices(), "ServiceId", "Description");
            EmployeeService employeeService = new EmployeeService
            {
                EmployeeId = (int)id
            };

            return(View(employeeService));
        }
Exemplo n.º 17
0
        internal void RefreshCache()
        {
            List <DbFavorite> newlyLoaded  = LoadFromDatabase();
            List <DbFavorite> oldFavorites = this.Cached;
            List <DbFavorite> missing      = ListsHelper.GetMissingSourcesInTarget(newlyLoaded, oldFavorites, new ByIdComparer <DbFavorite>());
            List <DbFavorite> redundant    = ListsHelper.GetMissingSourcesInTarget(oldFavorites, newlyLoaded, new ByIdComparer <DbFavorite>());
            List <DbFavorite> toUpdate     = newlyLoaded.Intersect(oldFavorites, new ChangedVersionComparer()).ToList();

            this.cache.Add(missing);
            this.cache.Delete(redundant);
            this.cache.Update(toUpdate);
            this.RefreshCachedItems();

            var missingToReport   = missing.Cast <IFavorite>().ToList();
            var redundantToReport = redundant.Cast <IFavorite>().ToList();
            var updatedToReport   = toUpdate.Cast <IFavorite>().ToList();

            this.dispatcher.ReportFavoritesAdded(missingToReport);
            this.dispatcher.ReportFavoritesDeleted(redundantToReport);
            this.dispatcher.ReportFavoritesUpdated(updatedToReport);
        }
Exemplo n.º 18
0
        // GET: Businesses/Create
        public ActionResult Create()
        {
            User user = db.Users
                        .Where(u => u.UserName == User.Identity.Name)
                        .FirstOrDefault();

            if (user != null)
            {
                ViewBag.AddressId = new SelectList(ListsHelper.GetUserAddresses(user.UserId), "AddressId", "Description");

                Business business = new Business
                {
                    UserId       = user.UserId,
                    AddedDate    = DateTime.Now,
                    ModifiedDate = DateTime.Now
                };
                return(View(business));
            }
            ViewBag.AddressId = new SelectList(ListsHelper.GetUserAddresses(0), "AddressId", "Description");
            return(View());
        }
Exemplo n.º 19
0
        public ActionResult Create(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Employee employee = db.Employees.Find(id);

            if (employee == null)
            {
                return(HttpNotFound());
            }

            if (!UsersHelper.IsEmployeeOfCurrentBusiness(User, (int)id))
            {
                return(RedirectToAction("BusinessCustomers"));
            }

            User user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            string actionName = ControllerContext.RouteData.Values["action"].ToString();

            ViewBag.ReturnUrl      = string.Format("~/ClientLists/{0}/{1}", actionName, id);
            ViewBag.ServiceId      = new SelectList(ListsHelper.GetEmployeeServices((int)id), "ServiceId", "Description");
            ViewBag.CustomerId     = new SelectList(ListsHelper.GetCustomers(true, user.UserId), "CustomerId", "CustomerName");
            ViewBag.EmployeeName   = employee.User.Name;
            ViewBag.EmployeeUserId = employee.User.UserId;

            ClientList clientList = new ClientList
            {
                EmployeeId  = (int)id,
                Appointment = DateTime.Now
            };

            return(View(clientList));
        }
Exemplo n.º 20
0
        public ActionResult CreateMe([Bind(Include = "ClientListId,ListStatusId,CustomerId,EmployeeId,ServiceId,Appointment")] ClientList clientList)
        {
            DateTime now  = DateTime.Now;
            User     user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();

            if (UsersHelper.IsEmployeeOfCurrentBusiness(User, clientList.EmployeeId))
            {
                return(RedirectToAction("Create", new { clientList = clientList }));
            }

            if (clientList.Appointment < now.Subtract(new TimeSpan(0, 2, 0)))
            {
                ModelState.AddModelError("Appointment", "Value must be greater than or equal to {now}");
            }

            if (ModelState.IsValid)
            {
                clientList.AddedByUserId    = user.UserId;
                clientList.AddedDate        = now;
                clientList.ModifiedByUserId = user.UserId;
                clientList.ModifiedDate     = now;

                db.ClientLists.Add(clientList);
                db.SaveChanges();
                return(RedirectToAction("EmployeeCustomers", new { id = clientList.EmployeeId }));
            }

            string actionName = ControllerContext.RouteData.Values["action"].ToString();

            ViewBag.ReturnUrl    = string.Format("~/ClientLists/{0}/{1}", actionName, clientList.EmployeeId);
            ViewBag.ServiceId    = new SelectList(ListsHelper.GetEmployeeServices(clientList.EmployeeId), "ServiceId", "Description", clientList.EmployeeId);
            ViewBag.CustomerId   = new SelectList(ListsHelper.GetCustomers(false, user.UserId), "CustomerId", "CustomerName", clientList.CustomerId);
            ViewBag.EmployeeName = UsersHelper.EmployeeUser(clientList.EmployeeId).Name;

            return(View(clientList));
        }
Exemplo n.º 21
0
 // GET: ListStatus/Create
 public ActionResult Create()
 {
     ViewBag.PriorityLevelId = new SelectList(ListsHelper.GetPriorityLevels(), "PriorityLevelId", "Description");
     return(View());
 }
Exemplo n.º 22
0
 public ActionResult BusinessCustomers()
 {
     return(View(ListsHelper.GetBusinessCustomers(User.Identity.Name)));
 }