public void CreateRestaurantCategory(RestaurantCategory res) { JustFeastDbDataContext db = new JustFeastDbDataContext(); db.ResCats.InsertOnSubmit(RestaurantCtrl.ConvertRestaurantCategoryToDatabase(res)); db.SubmitChanges(); }
public IActionResult EditResturantCategory([FromBody] RestaurantCategoryUpdateDTO restaurantRequest, int id) { if (restaurantRequest == null) { return(BadRequest("Request is null!")); } if (!ModelState.IsValid) { return(BadRequest("Data validation errors!")); } RestaurantCategory restaurantCategory = restaurantService.GetRestaurantCategoryById(id); if (restaurantCategory == null) { return(NotFound()); } restaurantCategory.Name = restaurantRequest.Name; restaurantCategory.Priority = restaurantRequest.Priority; restaurantCategory.DateUpdated = DateTime.Now; var response = restaurantService.UpdateRestaurantCategory(restaurantCategory); return(Ok(response)); }
public IHttpActionResult PutRestaurantCategory(int id, RestaurantCategory restaurantCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != restaurantCategory.RestaurantCategoryID) { return(BadRequest()); } db.Entry(restaurantCategory).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RestaurantCategoryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult DeleteConfirmed(int id) { RestaurantCategory restaurantcategory = db.RestaurantCategories.Find(id); db.RestaurantCategories.Remove(restaurantcategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public bool UpdateRestaurantCategory(RestaurantCategory restaurantCategory) { Condition.WithExceptionOnFailure <InvalidParameterException>() .Requires(restaurantCategory, "restaurantCategory") .IsNotNull(); return(_restaurantCategoryRepository.Update(restaurantCategory)); }
public void UpdateRestaurantCategory(RestaurantCategory res) { JustFeastDbDataContext db = new JustFeastDbDataContext(); var nres = db.ResCats.First(x => x.id == res.Id); nres.name = res.Name; db.SubmitChanges(); }
public ActionResult Update(UpdateRestaurantVm data) { var restaurant = service.Uow.Restaurants.GetById(data.RestaurantId); restaurant.Name = data.RestaurantName; restaurant.Adress = data.Adress; restaurant.PhoneNumber = data.PhoneNumber; restaurant.DistrictId = data.DistrictId; restaurant.LastUpdatedDate = DateTime.Now; if (data.RestaurantImage != null) { if (System.IO.File.Exists(Server.MapPath(restaurant.CoverImagePath))) { System.IO.File.Delete(Server.MapPath(restaurant.CoverImagePath)); } WebImage img = new WebImage(data.RestaurantImage.InputStream); img.Resize(640, 360, false); string fileName = restaurant.Id + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfffffff"); img.FileName = fileName + "." + img.ImageFormat; restaurant.CoverImagePath = "/Content/Images/CoverPics/" + img.FileName; img.Save(Server.MapPath("/Content/Images/CoverPics/") + img.FileName); } service.Uow.Restaurants.Update(restaurant); if (data.FeatureIds != null) { service.Uow.RestaurantFeatures.DeleteByRestaurantId(data.RestaurantId); foreach (var featureId in data.FeatureIds) { var restaurantFeature = new RestaurantFeature() { RestaurantId = data.RestaurantId, FeatureId = featureId }; service.Uow.RestaurantFeatures.Insert(restaurantFeature); } } if (data.CategoryIds != null) { service.Uow.RestaurantCategories.DeleteByRestaurantId(data.RestaurantId); foreach (var categoryId in data.CategoryIds) { var restaurantCategory = new RestaurantCategory() { RestaurantId = data.RestaurantId, CategoryId = categoryId }; service.Uow.RestaurantCategories.Insert(restaurantCategory); } } service.Uow.Save(); return(RedirectToAction("List")); }
public void DeleteRestaurantCategory(RestaurantCategory restaurantCategory) { if (restaurantCategory == null) { throw new Exception("Category cannot be null"); } uow.RestaurantCategoryRepository.Remove(restaurantCategory); uow.Complete(); }
// // GET: /RestCategory/Delete/5 public ActionResult Delete(int id = 0) { RestaurantCategory restaurantcategory = db.RestaurantCategories.Find(id); if (restaurantcategory == null) { return(HttpNotFound()); } return(View(restaurantcategory)); }
public ActionResult Edit(RestaurantCategory restaurantcategory) { if (ModelState.IsValid) { db.Entry(restaurantcategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(restaurantcategory)); }
public async Task <bool> UpdateRestaurantCategoryAsync(RestaurantCategory restaurantCategoryToUpdate) { _context.RestaurantCategories .Update(restaurantCategoryToUpdate); var updated = await _context .SaveChangesAsync(); return(updated > 0); }
public async Task <bool> CreateRestaurantCategoryAsync(RestaurantCategory restaurantCategory) { await _context.RestaurantCategories .AddAsync(restaurantCategory); var created = await _context .SaveChangesAsync(); return(created > 0); }
public IActionResult Remove(int[] categoryIds) { foreach (int categoryId in categoryIds) { RestaurantCategory theCategory = context.Categories.Single(c => c.ID == categoryId); context.Categories.Remove(theCategory); } context.SaveChanges(); return(Redirect("/category")); }
public IActionResult EditCategory(int ID) { RestaurantCategory categoryToEdit = context.Categories.First(c => c.ID == ID); EditCategoryViewModel editCategoryViewModel = new EditCategoryViewModel() { Name = categoryToEdit.Name, ID = categoryToEdit.ID }; return(View(editCategoryViewModel)); }
public IHttpActionResult GetRestaurantCategory(int id) { RestaurantCategory restaurantCategory = db.RestaurantCategories.Find(id); if (restaurantCategory == null) { return(NotFound()); } return(Ok(restaurantCategory)); }
public ActionResult Create(RestaurantCategory restaurantcategory) { if (ModelState.IsValid) { db.RestaurantCategories.Add(restaurantcategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(restaurantcategory)); }
public RestaurantCategory CreateNewRestaurantCategory(RestaurantCategory restaurantCategory) { if (restaurantCategory == null) { throw new Exception("Category cannot be null"); } uow.RestaurantCategoryRepository.Add(restaurantCategory); uow.Complete(); return(restaurantCategory); }
public async Task <RestaurantCategory> UpdateRestaurantCategory(RestaurantCategory restaurantCategory) { if (restaurantCategory == null) { throw new Exception("Category cannot be null"); } uow.Complete(); return(restaurantCategory); }
public bool AddRestaurantCategory(RestaurantCategory restaurantCategory) { Condition.WithExceptionOnFailure <InvalidParameterException>() .Requires(restaurantCategory, "restaurantCategory") .IsNotNull(); var resultAdd = _restaurantCategoryRepository.Add(restaurantCategory); _restaurantCategoryRepository.Save(); return(resultAdd); }
public IHttpActionResult PostRestaurantCategory(RestaurantCategory restaurantCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.RestaurantCategories.Add(restaurantCategory); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = restaurantCategory.RestaurantCategoryID }, restaurantCategory)); }
public async Task <ActionResult> Delete(int id, RestaurantCategory cat) { try { await _proxy.DeleteRestaurantCategoryAsync(id); return(RedirectToAction("Index")); } catch { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public IActionResult EditCategory(EditCategoryViewModel editCategoryViewModel) { int ID = editCategoryViewModel.ID; RestaurantCategory updatedCategory = context.Categories.First(c => c.ID == ID); updatedCategory.Name = editCategoryViewModel.Name; updatedCategory.ID = editCategoryViewModel.ID; context.Categories.Update(updatedCategory); context.SaveChanges(); return(Redirect("/category")); }
public static RestaurantCategory ConvertRestaurantCategoryToModel(ResCat cat) { if (cat == null) { return(null); } var resCat = new RestaurantCategory { Id = cat.id, Name = cat.name }; return(resCat); }
public static ResCat ConvertRestaurantCategoryToDatabase(RestaurantCategory cat) { if (cat == null) { return(null); } var resCat = new ResCat { id = cat.Id, name = cat.Name }; return(resCat); }
public IHttpActionResult DeleteRestaurantCategory(int id) { RestaurantCategory restaurantCategory = db.RestaurantCategories.Find(id); if (restaurantCategory == null) { return(NotFound()); } db.RestaurantCategories.Remove(restaurantCategory); db.SaveChanges(); return(Ok(restaurantCategory)); }
public bool UpdateRestaurantCategory(RestaurantCategory restaurantCategory) { try { return(_restaurantService.UpdateRestaurantCategory(restaurantCategory)); } catch (EnterpriseException enterpriseException) { throw new FaultException <EnterpriseException>(enterpriseException, enterpriseException.Message, new FaultCode(enterpriseException.ErrorCode)); } catch (Exception exception) { throw new FaultException <Exception>(exception, exception.Message); } }
public IActionResult DeleteRestaurantCategory(int Id = 0) { if (Id == 0) { return(BadRequest("Category is null!")); } RestaurantCategory restaurantCategory = restaurantService.GetRestaurantCategoryById(Id); if (restaurantCategory == null) { return(NotFound()); } restaurantService.DeleteRestaurantCategory(restaurantCategory); return(Ok()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } RestaurantCategory = await _context.RestaurantCategories.FindAsync(id); if (RestaurantCategory != null) { _context.RestaurantCategories.Remove(RestaurantCategory); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public IActionResult Add(AddCategoryViewModel addCategoryViewModel) { if (ModelState.IsValid) { RestaurantCategory newCategory = new RestaurantCategory { Name = addCategoryViewModel.Name }; context.Categories.Add(newCategory); context.SaveChanges(); return(Redirect("/Category")); } return(View(addCategoryViewModel)); }
public async Task <IActionResult> CreateRestaurantCategory([FromBody] CreateRestaurantCategoryRequest createRestaurantCategoryRequest) { var newRestaurantCategoryId = new Guid(); var restaurantCategory = new RestaurantCategory { Id = newRestaurantCategoryId, RestaurantCategoryName = createRestaurantCategoryRequest.RestaurantCategoryName }; await _restaurantCategoryService .CreateRestaurantCategoryAsync(restaurantCategory); /*var locationUri = _uriService.GetRestaurantUri(restaurant.Id.ToString()); * return Created(locationUri, new Response<RestaurantResponse>(_mapper.Map<RestaurantResponse>(restaurant)));*/ return(Ok(new Response <RestaurantCategoryResponse>(_mapper.Map <RestaurantCategoryResponse>(restaurantCategory)))); }