Exemplo n.º 1
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.º 2
0
        public async Task <IHttpActionResult> PutCustomer(int id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.CustomerId)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutUserFavoriteBusiness(int id, [FromBody] UserFavoriteBusiness userFavoriteBusiness)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userFavoriteBusiness.UserFavoriteBusinessId)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserFavoriteBusinessExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "CountryId,Code,Name")] Country country)
 {
     if (ModelState.IsValid)
     {
         db.Entry(country).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(country));
 }
Exemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "ServiceId,Description")] Service service)
 {
     if (ModelState.IsValid)
     {
         db.Entry(service).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(service));
 }
Exemplo n.º 6
0
 public ActionResult Edit([Bind(Include = "CustomerId,UserId,CustomerName")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Exemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "PriorityLevelId,Description,Value")] PriorityLevel priorityLevel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(priorityLevel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(priorityLevel));
 }
Exemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "EmployeeId,ServiceId,IsDisabled")] EmployeeService employeeService)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employeeService).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { eId = employeeService.EmployeeId, sId = employeeService.ServiceId }));
     }
     ViewBag.ServiceId = new SelectList(ListsHelper.GetServices(), "ServiceId", "Description", employeeService.ServiceId);
     return(View(employeeService));
 }
Exemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "ListStatusId,Description,PriorityLevelId,Active,Completed,SystemStatus,Canceled,Unconfirmed,Confirmed,Current")] ListStatus listStatus)
 {
     if (ModelState.IsValid)
     {
         db.Entry(listStatus).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PriorityLevelId = new SelectList(db.PriorityLevels, "PriorityLevelId", "Description", listStatus.PriorityLevelId);
     return(View(listStatus));
 }
Exemplo n.º 10
0
        public ActionResult Edit([Bind(Include = "EmployeeId,BusinessId,UserId,Email,IsDisabled,EmployeePhoneHidden,RatingReviewDisabled")] Employee employee)
        {
            ModelState.Remove("Email");
            employee.Email = db.Users.Find(employee.UserId).UserName;

            if (ModelState.IsValid)
            {
                db.Entry(employee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Details", "Businesses", new { id = employee.BusinessId }));
            }

            return(View(employee));
        }
Exemplo n.º 11
0
        public ActionResult Create([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.AddedDate    = DateTime.Now;
                business.ModifiedDate = DateTime.Now;

                db.Businesses.Add(business);

                Response response = DBHelper.SaveChanges(db);
                if (response.Succeeded)
                {
                    if (business.BannerFile != null)
                    {
                        string 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;
                            db.SaveChanges();
                        }
                    }
                    User user = db.Users.Find(business.UserId);
                    UsersHelper.AddUserToRole(user.UserName, "Owner");
                    return(RedirectToAction("Create", "Employees", new { id = business.BusinessId }));
                }
                ModelState.AddModelError(string.Empty, response.Message);
            }

            ViewBag.AddressId = new SelectList(ListsHelper.GetUserAddresses(business.UserId), "AddressId", "Description", business.AddressId);
            return(View(business));
        }
Exemplo n.º 12
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.º 13
0
        public ActionResult Edit([Bind(Include = "UserId,UserName,Nickname,FirstName,LastName,Phone,Picture,PictureFile")] User user)
        {
            if (string.IsNullOrEmpty(user.FirstName) || user.FirstName.Trim() == string.Empty)
            {
                ModelState.AddModelError("FirstName", "This field is required");
            }

            if (string.IsNullOrEmpty(user.LastName) || user.LastName.Trim() == string.Empty)
            {
                ModelState.AddModelError("LastName", "This field is required");
            }

            if (string.IsNullOrEmpty(user.Phone) || user.Phone.Trim() == string.Empty)
            {
                ModelState.AddModelError("Phone", "This field is required");
            }

            if (ModelState.IsValid)
            {
                BnBContext db2         = new BnBContext();
                User       currentUser = db2.Users.Find(user.UserId);
                if (currentUser.UserName != user.UserName)
                {
                    UsersHelper.UpdateUserName(currentUser.UserName, user.UserName);
                }
                if ((currentUser.FirstName != user.FirstName) ||
                    (currentUser.LastName != user.LastName) ||
                    (currentUser.Nickname != user.Nickname) ||
                    (currentUser.UserName != user.UserName))
                {
                    Customer customer = db.Customers
                                        .Where(c => c.UserId == user.UserId && c.IsAccountOwner == true)
                                        .FirstOrDefault();
                    customer.CustomerName    = user.Name;
                    db.Entry(customer).State = EntityState.Modified;
                }

                db2.Dispose();

                if (user.PictureFile != null)
                {
                    var    folder         = "~/Content/Pictures";
                    string pic            = string.Format("{0}{1}", user.UserId, Path.GetExtension(user.PictureFile.FileName));
                    bool   uploadResponse = FilesHelper.UploadImage(user.PictureFile, folder, pic);
                    if (uploadResponse)
                    {
                        user.Picture = string.Format("{0}/{1}", folder, pic);
                    }
                }

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

                Response response = DBHelper.SaveChanges(db);
                if (response.Succeeded)
                {
                    return(RedirectToAction("Details", new { id = user.UserId }));
                }
                ModelState.AddModelError(string.Empty, response.Message);
            }
            return(View(user));
        }