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)); }
public ActionResult Create([Bind(Include = "EmployeeId,BusinessId,Email,IsDisabled,EmployeePhoneHidden,RatingReviewDisabled")] Employee employee) { User currentUser = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); User employeeUser = db.Users.Where(eu => eu.UserName == employee.Email).FirstOrDefault(); if (employeeUser != null) { employee.UserId = employeeUser.UserId; if (ModelState.IsValid) { db.Employees.Add(employee); //TODO: Send Email/Notification to New Employee for CONFIRMIMATION db.SaveChanges(); UsersHelper.AddUserToRole(employeeUser.UserName, "Employee", currentUser.UserName); return(RedirectToAction("Details", "Businesses", new { id = employee.BusinessId })); } } else { ModelState.AddModelError(string.Empty, "Employee's Email wasn't found"); } return(View(employee)); }
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)); }
public ActionResult Create([Bind(Include = "CountryId,Code,Name")] Country country) { if (ModelState.IsValid) { db.Countries.Add(country); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(country)); }
public ActionResult Create([Bind(Include = "PriorityLevelId,Description,Value")] PriorityLevel priorityLevel) { if (ModelState.IsValid) { db.PriorityLevels.Add(priorityLevel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(priorityLevel)); }
public ActionResult Create([Bind(Include = "ServiceId,Description")] Service service) { if (ModelState.IsValid) { db.Services.Add(service); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(service)); }
public ActionResult Create([Bind(Include = "UserId,UserName,Nickname,FirstName,LastName,Phone,Picture,PictureFile")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
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)); }
public static User CreateUser(string email, string roleName) { UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(userContext)); ApplicationUser userASP = userManager.FindByEmail(email); User user = db.Users.Where(u => u.UserName == email).FirstOrDefault(); if (user == null) { user = new User { UserName = email, Picture = "~/Content/Pictures/place-holder.png" }; Customer customer = new Customer { UserId = user.UserId, CustomerName = user.UserName, IsAccountOwner = true }; db.Users.Add(user); db.Customers.Add(customer); db.SaveChanges(); AddUserToRole(email, roleName); return(user); } return(null); }
public static Response SaveChanges(BnBContext db) { try { db.SaveChanges(); return(new Response { Succeeded = true }); } catch (Exception ex) { var response = new Response { Succeeded = false }; if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("_Index")) { response.Message = "There is a record with the same value"; } else if (ex.InnerException != null && ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message.Contains("REFERENCE")) { response.Message = "There record can't be deleted because it has related records"; } else { response.Message = ex.Message; } return(response); } }
public ActionResult Create([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.Addresses.Add(address); db.SaveChanges(); return(Redirect(address.ReturnUrl)); } ViewBag.CountryId = new SelectList(ListsHelper.GetCountries(), "CountryId", "Name", address.CountryId); return(View(address)); }
public ActionResult Create([Bind(Include = "CustomerId,UserId,CustomerName,ReturnUrl")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); if (customer.ReturnUrl == null) { return(RedirectToAction("Index")); } return(Redirect(customer.ReturnUrl)); } ViewBag.UserId = new SelectList(db.Users, "UserId", "UserName", customer.UserId); return(View(customer)); }
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)); }
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)); }