Example #1
0
        public void CreateRestaurantCategory(RestaurantCategory res)
        {
            JustFeastDbDataContext db = new JustFeastDbDataContext();

            db.ResCats.InsertOnSubmit(RestaurantCtrl.ConvertRestaurantCategoryToDatabase(res));
            db.SubmitChanges();
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }
Example #4
0
        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));
        }
Example #6
0
        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();
 }
Example #9
0
        //
        // GET: /RestCategory/Delete/5

        public ActionResult Delete(int id = 0)
        {
            RestaurantCategory restaurantcategory = db.RestaurantCategories.Find(id);

            if (restaurantcategory == null)
            {
                return(HttpNotFound());
            }
            return(View(restaurantcategory));
        }
Example #10
0
 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));
        }
Example #15
0
        public IHttpActionResult GetRestaurantCategory(int id)
        {
            RestaurantCategory restaurantCategory = db.RestaurantCategories.Find(id);

            if (restaurantCategory == null)
            {
                return(NotFound());
            }

            return(Ok(restaurantCategory));
        }
Example #16
0
        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);
        }
Example #19
0
        public bool AddRestaurantCategory(RestaurantCategory restaurantCategory)
        {
            Condition.WithExceptionOnFailure <InvalidParameterException>()
            .Requires(restaurantCategory, "restaurantCategory")
            .IsNotNull();

            var resultAdd = _restaurantCategoryRepository.Add(restaurantCategory);

            _restaurantCategoryRepository.Save();

            return(resultAdd);
        }
Example #20
0
        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));
        }
Example #21
0
        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);
        }
Example #25
0
        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));
        }
Example #26
0
 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);
     }
 }
Example #27
0
        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());
        }
Example #28
0
        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))));
        }