public IHttpActionResult PutItem(int id, ItemDto itemDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var itemInDb = db.Items.SingleOrDefault(i => i.Id == id); if (id != itemDto.Id) { return(BadRequest()); } Mapper.Map(itemDto, itemInDb); //db.Entry(itemDto).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ItemExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutServiceProvider(int id, ServiceProvider serviceProvider) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != serviceProvider.Id) { return(BadRequest()); } db.Entry(serviceProvider).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ServiceProviderExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutLocation(int id, Location location) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != location.Id) { return(BadRequest()); } db.Entry(location).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LocationExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutCustomer(int id, CustomerDto customerDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var customerInDb = db.Customers.SingleOrDefault(c => c.Id == id); if (id != customerDto.Id) { return(BadRequest()); } Mapper.Map(customerDto, customerInDb); //db.Entry(customer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutServiceProvider(int id, ServiceProviderDto serviceProviderDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var serviceProviderInDb = db.ServiceProviders.SingleOrDefault(s => s.Id == id); if (id != serviceProviderDto.Id) { return(BadRequest()); } Mapper.Map(serviceProviderDto, serviceProviderInDb); //db.Entry(serviceProviderDto).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ServiceProviderExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutAdministrativeStaff(int id, AdminDto adminDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var adminInDb = db.AdministrativeStaffs.SingleOrDefault(a => a.Id == id); if (id != adminDto.Id) { return(BadRequest()); } Mapper.Map(adminDto, adminInDb); //db.Entry(administrativeStaff).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AdministrativeStaffExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "Id,Latitude,Longitude,Type")] Location location) { if (ModelState.IsValid) { db.Locations.Add(location); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(location)); }
public ActionResult Create([Bind(Include = "Id,ReqId,ModifiedDate,value,Comment")] RequestProgress requestProgress) { if (ModelState.IsValid) { db.RequestProgreses.Add(requestProgress); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ReqId = new SelectList(db.ItemRequests, "Id", "Message", requestProgress.ReqId); return(View(requestProgress)); }
public ActionResult Create([Bind(Include = "Id,DateAndTime,Amount,RequestId")] ItemPayment itemPayment) { if (ModelState.IsValid) { db.ItemPayments.Add(itemPayment); db.SaveChanges(); return(RedirectToAction("Details", "ItemPayments", new { id = itemPayment.Id })); } ViewBag.RequestId = new SelectList(db.ItemRequests, "Id", "Message", itemPayment.RequestId); return(View(itemPayment)); }
public ActionResult Create([Bind(Include = "Id,Username,FirstName,LastName,CreatedDate,ModifiedDate,ApplicationUserId")] AdministrativeStaff administrativeStaff) { if (ModelState.IsValid) { db.AdministrativeStaffs.Add(administrativeStaff); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ApplicationUserId = new SelectList(db.AspNetUsers, "Id", "Email", administrativeStaff.ApplicationUserId); return(View(administrativeStaff)); }
public ActionResult Create([Bind(Include = "Id,ItemId,PropertyName,Value")] ItemProperty itemProperty) { if (ModelState.IsValid) { db.ItemProperties.Add(itemProperty); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ItemId = new SelectList(db.Items, "Id", "ItemName", itemProperty.ItemId); return(View(itemProperty)); }
public ActionResult Create([Bind(Include = "Id,Username,Password,BasedCity,MailingAddress,Bio,FirstName,LastName,DateOfBirth,Telephone,CompanyName,CompanyRegNo,StartedDate,Avatar,StatusId,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate,TypeId,MembershipTypeId")] ServiceProvider serviceProvider) { if (ModelState.IsValid) { db.ServiceProviders.Add(serviceProvider); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StatusId = new SelectList(db.Statuses, "Id", "Name", serviceProvider.StatusId); ViewBag.TypeId = new SelectList(db.ServiceProviderTypes, "Id", "Type", serviceProvider.TypeId); return(View(serviceProvider)); }
public ActionResult Create([Bind(Include = "Id,PostId,ContentOfComment,UserId")] BlogPostComment blogPostComment) { if (ModelState.IsValid) { db.BlogPostComments.Add(blogPostComment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PostId = new SelectList(db.BlogPosts, "Id", "PostContent", blogPostComment.PostId); ViewBag.UserId = db.BlogPostComments.Include(b => b.BlogPost).Include(b => b.Customer.Id).SingleOrDefault(b => b.Customer.Id == blogPostComment.UserId); //ViewBag.UserId = new SelectList(db.Customers, "Id", "Username", blogPostComment.UserId); return(View(blogPostComment)); }
public ActionResult Create([Bind(Include = "Id,PostUser,ReceivedUser,Rate,RequestId")] RatingsServiceProvider ratingsServiceProvider) { if (ModelState.IsValid) { db.RatingsServiceProviders.Add(ratingsServiceProvider); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PostUser = new SelectList(db.Customers, "Id", "Username", ratingsServiceProvider.PostUser); ViewBag.RequestId = new SelectList(db.ItemRequests, "Id", "Message", ratingsServiceProvider.RequestId); ViewBag.ReceivedUser = new SelectList(db.ServiceProviders, "Id", "Username", ratingsServiceProvider.ReceivedUser); return(View(ratingsServiceProvider)); }
public ActionResult Create(BlogPost blogPost) { if (ModelState.IsValid) { db.BlogPosts.Add(blogPost); db.SaveChanges(); return(RedirectToAction("Posted")); } ViewBag.CategoryId = new SelectList(db.BlogCategories, "Id", "Category", blogPost.CategoryId); ViewBag.UserId = new SelectList(db.ServiceProviders, "Id", "Username", blogPost.UserId); return(View(blogPost)); }
public ActionResult Create([Bind(Include = "Username,FirstName,LastName,DateOfBirth,Telephone,Gender,Address,StatusId,CreatedDate,ModifiedDate,IsSubscribedToNewsletter,ApplicationUserId")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); //return RedirectToAction("Index"); //return RedirectToAction("MyProfile","Customers", new { id = customer.Id }); return(RedirectToAction("MyProfile", "Customers", new { id = User.Identity.GetUserId() })); } ViewBag.StatusId = new SelectList(db.Statuses, "Id", "Name", customer.StatusId); //ViewBag.ApplicationUserId = new SelectList(db.AspNetUsers, "Id", "Username"); return(View(customer)); }
public ActionResult Create(ItemLocations itemLocations) { var item = db.Items.SingleOrDefault(i => i.Id == itemLocations.ItemId); if (ModelState.IsValid) { db.ItemLocations.Add(itemLocations); db.SaveChanges(); return(RedirectToAction("Index", "ItemLocations", new { iid = item.Id })); //return RedirectToAction("Index"); } ViewBag.ItemId = new SelectList(db.Items, "Id", "ItemName", itemLocations.ItemId); return(View(itemLocations)); }
public ActionResult Create([Bind(Include = "Id,Message,CreatedDate,AcceptedDate,ExpDate,CompletedDate,StatusId,LocationId,CustomerId,ServiceProviderId,ItemId,Latitude,Longitude")] ItemRequest itemRequest) { if (ModelState.IsValid) { db.ItemRequests.Add(itemRequest); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Username", itemRequest.CustomerId); ViewBag.ItemId = new SelectList(db.Items, "Id", "ItemName", itemRequest.ItemId); ViewBag.StatusId = new SelectList(db.ItemRequestStatuses, "Id", "Name", itemRequest.StatusId); ViewBag.ServiceProviderId = new SelectList(db.ServiceProviders, "Id", "Username", itemRequest.ServiceProviderId); return(View(itemRequest)); }
public ActionResult Create(Complain complain) { if (ModelState.IsValid) { db.Complains.Add(complain); db.SaveChanges(); return(RedirectToAction("ThankYou")); } //ViewBag.ComplainedBy = new SelectList(db.AspNetUsers, "Id", "Email"); //ViewBag.ComplainedAbout = new SelectList(db.AspNetUsers, "Id", "Email", complain.ComplainedAbout); //ViewBag.ActionId = new SelectList(db.ComplainActions, "Id", "Action", complain.ActionId); return(View(complain)); }
public ActionResult Create([Bind(Include = "Id,UserId,Price,Status")] Orders orders) { if (ModelState.IsValid) { db.Order.Add(orders); db.SaveChanges(); ViewBag.price = orders.Price; ViewBag.orderNumber = orders.Id; return(RedirectToAction("payment", orders)); // return View("payment", "Orders"); } ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", orders.UserId); ViewBag.Status = new SelectList(db.OrderStatus, "Id", "Action", orders.Status); return(View(orders)); }
public ActionResult Create(Item item) { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); return(RedirectToAction("Create", "PublishedItems", new { id = item.Id, user = item.UserId })); } ViewBag.StatusId = new SelectList(db.ItemStatus, "Id", "Name", item.StatusId); ViewBag.SubCategoryId = new SelectList(db.ItemSubCategories, "Id", "Name", item.SubCategoryId); ViewBag.TypeId = new SelectList(db.ItemTypes, "Id", "Type", item.TypeId); ViewBag.UserId = new SelectList(db.ServiceProviders, "Id", "Username", item.UserId); return(View(item)); }
public ActionResult Create(PublishedItem publishedItem) { if (ModelState.IsValid) { db.PublishedItems.Add(publishedItem); try { db.SaveChanges(); } catch (SqlException e) { throw e; } return(RedirectToAction("Index")); } ViewBag.ItemId = new SelectList(db.Items, "Id", "ItemName", publishedItem.ItemId); ViewBag.UserId = new SelectList(db.ServiceProviders, "Id", "Username", publishedItem.UserId); return(View(publishedItem)); }
public ActionResult Create([Bind(Include = "Id,Message,CreatedDate,AcceptedDate,ExpDate,CompletedDate,StatusId,LocationId,CustomerId,ServiceProviderId,ItemId,Latitude,Longitude")] ItemRequest itemRequest) { if (ModelState.IsValid) { db.ItemRequests.Add(itemRequest); db.SaveChanges(); //return RedirectToAction("Index"); if (itemRequest.Message != null) { //QxF+O9qg6fk-a9dYLek4plJk8JARdZ2081qRlIWKtz String message = HttpUtility.UrlEncode(itemRequest.Message); var sp = db.ServiceProviders.SingleOrDefault(i => i.Id == itemRequest.ServiceProviderId); String number = sp.Telephone; using (var wb = new WebClient()) { byte[] response = wb.UploadValues("https://api.txtlocal.com/send/", new NameValueCollection() { { "apikey", "EXfapgBZ+4M-qSpQCEdOLhG6ZEc0y7esVVeTi6rL41" }, { "numbers", "+94" + number }, { "message", message }, { "sender", "CLK Alert" } }); string result = System.Text.Encoding.UTF8.GetString(response); //return Content(result); } } return(RedirectToAction("Create", "ItemPayments", new { id = itemRequest.Id })); // return View("Views/ItemPayments/Create.cshtml"); // return RedirectToAction("Confirming"); } ViewBag.StatusId = new SelectList(db.ItemRequestStatuses, "Id", "Name", itemRequest.StatusId); ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Username", itemRequest.CustomerId); ViewBag.ItemId = new SelectList(db.Items, "Id", "ItemName", itemRequest.ItemId); ViewBag.ServiceProviderId = new SelectList(db.ServiceProviders, "Id", "Username", itemRequest.ServiceProviderId); return(View(itemRequest)); }
public ActionResult Upload(int id, HttpPostedFileBase file) { ItemImage itemImage = new ItemImage(); //var ItemId = h.ItemId; itemImage.ItemId = id; itemImage.Image = file.FileName; byte[] data = new byte[file.ContentLength]; file.InputStream.Read(data, 0, file.ContentLength); itemImage.ImageData = data; //if (file.ContentLength>(2*1024*1024)) //{ // ModelState.AddModelError("CustomError", "File size must be less than 2MB"); // return View(); //} //if (!(file.ContentType == "image/jpeg" || file.ContentType == "image/png")) //{ // ModelState.AddModelError("CustomError", "File types allowed: jpeg, png"); // return View(); //} var model = new ItemImageViewModel { Image = file.FileName, ImageData = data, File = file, }; using (ConstructionLKContext db = new ConstructionLKContext()) { if (ModelState.IsValid) { db.ItemImages.Add(itemImage); try { db.SaveChanges(); } catch (System.Data.Entity.Infrastructure.DbUpdateException e) { throw e; } } } return(RedirectToAction("Gallery", new { id = id })); }
public ActionResult Create(ServiceProvider serviceProvider, HttpPostedFileBase file) { //Console.WriteLine(">>>>>>>>>>>>>Create"); //if (ModelState.IsValid) //{ // Console.WriteLine(">>>>>>>>>>>>>Valid"); // db.ServiceProviders.Add(serviceProvider); // try // { // Console.WriteLine(">>>>>>>>>>>>>Save"); // db.SaveChanges(); // } // catch (Exception e) // { // Console.WriteLine(e); // throw; // } // return RedirectToAction("MyProfile", "ServiceProvidersCooperate", new { id = User.Identity.GetUserId() }); // //return RedirectToAction("Index"); //} //ViewBag.MembershipTypeId = new SelectList(db.MembershipTypes, "Id", "Name", serviceProvider.MembershipTypeId); ////ViewBag.TypeId = new SelectList(db.ServiceProviderTypes, "Id", "Type", serviceProvider.TypeId); //return View(serviceProvider); if (!(file == null)) { if (ModelState.IsValid) { file.SaveAs(Path.Combine(Server.MapPath("~/Resources/ProfilePicturesSP/"), Path.GetFileName(file.FileName))); db.ServiceProviders.Add(new ServiceProvider { Id = serviceProvider.Id, Username = serviceProvider.Username, MembershipTypeId = serviceProvider.MembershipTypeId, BasedCity = serviceProvider.BasedCity, MailingAddress = serviceProvider.MailingAddress, Bio = serviceProvider.Bio, FirstName = serviceProvider.FirstName, LastName = serviceProvider.LastName, DateOfBirth = serviceProvider.DateOfBirth, Telephone = serviceProvider.Telephone, StartedDate = serviceProvider.StartedDate, Avatar = "~/Resources/ProfilePicturesSP/" + Path.GetFileName(file.FileName), StatusId = serviceProvider.StatusId, CreatedBy = serviceProvider.CreatedBy, CreatedDate = serviceProvider.CreatedDate, ModifiedBy = serviceProvider.ModifiedBy, ModifiedDate = serviceProvider.ModifiedDate, TypeId = serviceProvider.TypeId, CompanyName = serviceProvider.CompanyName, CompanyRegNo = serviceProvider.CompanyRegNo, ApplicationUserId = serviceProvider.ApplicationUserId }); db.SaveChanges(); return(RedirectToAction("MyProfile", "ServiceProvidersCooperate", new { user = User.Identity.GetUserId() })); } } else { if (ModelState.IsValid) { db.ServiceProviders.Add(serviceProvider); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); throw; } return(RedirectToAction("MyProfile", "ServiceProvidersCooperate", new { user = User.Identity.GetUserId() })); //return RedirectToAction("Index"); } } ViewBag.MembershipTypeId = new SelectList(db.MembershipTypes, "Id", "Name", serviceProvider.MembershipTypeId); //ViewBag.TypeId = new SelectList(db.ServiceProviderTypes, "Id", "Type", serviceProvider.TypeId); return(View(serviceProvider)); //} }
//public ActionResult Create([Bind(Include = "Id,Username,MembershipTypeId,BasedCity,MailingAddress,Bio,FirstName,LastName,DateOfBirth,Telephone,CompanyName,CompanyRegNo,StartedDate,Avatar,StatusId,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate,TypeId,ApplicationUserId")] ServiceProvider serviceProvider) public ActionResult Create(ServiceProvider serviceProvider, HttpPostedFileBase file) { //string path = Path.Combine(Server.MapPath("~/Resources/ProfilePicturesSP/"), Path.GetFileName(file.FileName)); //using (ConstructionLKContext db = new ConstructionLKContext()) //{ if (!(file == null)) { if (ModelState.IsValid) { file.SaveAs(Path.Combine(Server.MapPath("~/Resources/ProfilePicturesSP/"), Path.GetFileName(file.FileName))); db.ServiceProviders.Add(new ServiceProvider { Id = serviceProvider.Id, Username = serviceProvider.Username, MembershipTypeId = serviceProvider.MembershipTypeId, BasedCity = serviceProvider.BasedCity, MailingAddress = serviceProvider.MailingAddress, Bio = serviceProvider.Bio, FirstName = serviceProvider.FirstName, LastName = serviceProvider.LastName, DateOfBirth = serviceProvider.DateOfBirth, Telephone = serviceProvider.Telephone, StartedDate = serviceProvider.StartedDate, Avatar = "~/Resources/ProfilePicturesSP/" + Path.GetFileName(file.FileName), StatusId = serviceProvider.StatusId, CreatedBy = serviceProvider.CreatedBy, CreatedDate = serviceProvider.CreatedDate, ModifiedBy = serviceProvider.ModifiedBy, ModifiedDate = serviceProvider.ModifiedDate, TypeId = serviceProvider.TypeId, //CompanyName = serviceProvider.CompanyName, //CompanyRegNo = serviceProvider.CompanyRegNo, ApplicationUserId = serviceProvider.ApplicationUserId } /*serviceProvider*/); try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine(">>>>>>Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw e; } //return RedirectToAction("Index"); return(RedirectToAction("MyProfile", "ServiceProvidersIndividual", new { user = User.Identity.GetUserId() })); } } else { if (ModelState.IsValid) { db.ServiceProviders.Add(serviceProvider); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); throw; } return(RedirectToAction("MyProfile", "ServiceProvidersIndividual", new { user = User.Identity.GetUserId() })); //return RedirectToAction("Index"); } } ViewBag.MembershipTypeId = new SelectList(db.MembershipTypes, "Id", "Name", serviceProvider.MembershipTypeId); //ViewBag.TypeId = new SelectList(db.ServiceProviderTypes, "Id", "Type", serviceProvider.TypeId); return(View(serviceProvider)); //} }