Exemplo n.º 1
0
        public async Task <bool> UpdateRestaurantAsync(int id, RestaurantModel restaurant)
        {
            await GetRestaurantAsync(id);

            restaurant.Id = id;

            repository.UpdateRestaurant(mapper.Map <RestaurantEntity>(restaurant));
            var res = await repository.SaveChangesAsync();

            if (res)
            {
                return(true);
            }

            throw new Exception("Database Exception");
        }
Exemplo n.º 2
0
        public int Insert(RestaurantModel obj)
        {
            // arrange
            var dbModel = new RestaurantModel()
            {
                Name = "Test Restaurant"
            };

            // act
            var newId = new RestaurantRepository().Insert(dbModel);

            // assert
            Assert.IsTrue(newId > 0);

            return(newId);
        }
Exemplo n.º 3
0
        public RestaurantModel Delete(int id)
        {
            RestaurantModel model = new RestaurantModel();

            try
            {
                restaurantBusiness.Remove(id);
                model.ErrorSuccess = true;
            }
            catch (Exception ex)
            {
                model.ErrorSuccess   = false;
                model.ErrorNmMessage = ex.Message;
            }
            return(model);
        }
 public ActionResult <RestaurantModel> CreateRestaurant([FromBody] RestaurantModel restaurant)
 {
     try
     {
         var newRestaurant = service.CreateRestaurant(restaurant);
         return(Created($"/api/Restaurants/{newRestaurant.Id}", newRestaurant));
     }
     catch (NotFoundException ex)
     {
         return(NotFound(ex.Message));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
 public ActionResult <bool> UpdateRestaurant(int id, RestaurantModel restaurant)
 {
     try
     {
         var result = service.UpdateRestaurant(id, restaurant);
         return(Ok(result));
     }
     catch (NotFoundException ex)
     {
         return(NotFound(ex.Message));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
        public void CreateRestaurantFailNameTest()
        {
            RestaurantModel restaurantModel = new RestaurantModel()
            {
                City         = "Main City",
                EmailAddress = "*****@*****.**",
                PhoneNumber  = "32168",
            };

            // Setup Mock
            var httpRequest = CreateMockRequest(restaurantModel);
            var result      = RestaurantService.CreateRestaurant(httpRequest.Object, this.mockBlobContainer.Object, this.log, this.context).Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(BadRequestObjectResult), result.GetType());
        }
 public ActionResult EditRestaurant(RestaurantModel model)
 {
     if (ModelState.IsValid)
     {
         Restaurant restaurant = new Restaurant();
         restaurant.Name              = model.Name;
         restaurant.Active            = model.Active;
         restaurant.Description       = model.Description;
         restaurant.Email             = model.Email;
         restaurant.Username          = User.Identity.Name;
         restaurant.StreetAddress     = model.StreetAddress;
         restaurant.City              = model.City;
         restaurant.PostalCode        = model.PostalCode;
         restaurant.MaxGuests         = model.MaxGuests;
         restaurant.OpenTimes         = new List <OpenTime>();
         restaurant.OpenTimes         = model.OpenTimes.ToList();
         restaurant.Id                = model.Id;
         restaurant.MaxPersonsBooking = model.MaxPersonsBooking;
         restaurant.DayCapacity       = model.DayCapacity;
         if (model.Image != null)
         {
             if (model.ImageUrl != null)
             {
                 System.IO.File.Delete(Server.MapPath(model.ImageUrl));
             }
             string fileName = Guid.NewGuid().ToString() +
                               model.Image.FileName.Substring(model.Image.FileName.LastIndexOf('.'));
             var path = Path.Combine(Server.MapPath("~/Images/UserImages/"), fileName);
             model.Image.SaveAs(path);
             restaurant.ImageUrl = "/Images/UserImages/" + fileName;
         }
         if (model.ClosedDates != null)
         {
             var dates = model.ClosedDates.Split(',');
             restaurant.ClosedDates = new List <CloseDate>();
             foreach (var date in dates)
             {
                 restaurant.ClosedDates.Add(new CloseDate()
                 {
                     ClosedDate = DateTime.Parse(date)
                 });
             }
         }
         _restaurantService.UpdateRestaurant(restaurant);
     }
     return(View(model));
 }
Exemplo n.º 8
0
        // View Restaurant Details
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            var Chuu2 = new RestaurantModel();

            using (SqlConnection Rikka = new SqlConnection(Dekomori.GetConnection()))
            {
                Rikka.Open();
                string Takanashi = @"SELECT r.RSG_RName, r.RSG_Image, r.RSG_RName, u.RSG_Username, r.RSG_OperatingHours, c.RSG_CatID FROM RSG_Restaurants r INNER JOIN RSG_Categories c ON r.RSG_CatID = c.RSG_CatID
                               INNER JOIN RSG_Users u ON r.RSG_UserID = u.RSG_UserID 
                               WHERE r.RSG_RID = @RID";

                //"SELECT r.RSG_RID, r.RSG_Image, r.RSG_RName, u.RSG_Username, r.RSG_OperatingHours, c.RSG_Category FROM RSG_Restaurants r " +
                //"INNER JOIN RSG_Users u ON r.RSG_UserID = u.RSG_UserID " +
                //"INNER JOIN RSG_Categories c ON r.RSG_CatID = c.RSG_CatID"

                using (SqlCommand WickedEye = new SqlCommand(Takanashi, Rikka))
                {
                    WickedEye.Parameters.AddWithValue("@RID", id);
                    using (SqlDataReader Nibutani = WickedEye.ExecuteReader())
                    {
                        if (Nibutani.HasRows)
                        {
                            while (Nibutani.Read())
                            {
                                Chuu2.Restaurant     = Nibutani["RSG_RName"].ToString();
                                Chuu2.Image          = Nibutani["RSG_Image"].ToString();
                                Chuu2.Restaurant     = Nibutani["RSG_RName"].ToString();
                                Chuu2.UserName       = Nibutani["RSG_Username"].ToString();
                                Chuu2.OperatingHours = Nibutani["RSG_OperatingHours"].ToString();
                                Chuu2.CatID          = int.Parse(Nibutani["RSG_CatID"].ToString());
                            }

                            return(View(Chuu2));
                        }
                        else
                        {
                            return(RedirectToAction("Index"));
                        }
                    }
                }
            }
        }
 public IActionResult Put(int id, [FromBody] RestaurantModel restaurantModel)
 {
     try
     {
         restaurantModel.Id = id;
         var Restaurant = _restaurantService.Update(restaurantModel.ToDomainModel());
         if (Restaurant == null)
         {
             return(NotFound());
         }
         return(Ok(Restaurant.ToAPIModel()));
     }catch (Exception ex)
     {
         ModelState.AddModelError("UpdateRestaurant", ex.Message);
         return(BadRequest(ModelState));
     }
 }
        public Operation<RestaurantModel> UpdateRestaurant(RestaurantModel model)
        {

            return Operation.Create(() =>
            {
                //model.Validate();
                var isExist = _context.Restaurants.Find(model.RestId);
                if (isExist == null) throw new Exception("Restaurant does not exist");

                var entity = model.Edit(isExist, model);
                _context.Entry(entity).State = EntityState.Modified;
                _context.SaveChanges();
                

                return model;
            });
        }
Exemplo n.º 11
0
        public ActionResult EditRestaurant(RestaurantModel restaurant)
        {
            if (ModelState.IsValid)
            {
                int        restid     = adminrepo.GetIdFromEmail <Restaurant>(restaurant.Email);
                Restaurant restToEdit = restrepo.Get(restid);

                restToEdit.Name   = restaurant.Name;
                restToEdit.Status = restaurant.Status;
                restrepo.Update(restToEdit, restToEdit.Id);

                TempData["success"] = "Restaurant Edited Successfully";

                return(RedirectToAction("SearchRestaurant", "Admin"));
            }
            return(View(restaurant));
        }
Exemplo n.º 12
0
        private void addRestaurantBtn_Click(object sender, EventArgs e)
        {
            string restaurantName    = restaurantNameTB.Text;
            string restaurantAddress = restaurantAddressTB.Text;
            string _connectionString = "Data Source=" +
                                       Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\OO_PocketGourmet_REAL-UnitTest\MVPDB.sqlite;";
            RestaurantServices restaurantServices = new RestaurantServices(new RestaurantRepository(_connectionString), new ModelDataAnnotationCheck());
            RestaurantModel    restaurant         = new RestaurantModel()
            {
                RestaurantName    = restaurantName,
                RestaurantAddress = restaurantAddress,
            };

            restaurantServices.Add(restaurant);

            MessageBox.Show("Restaurant Added");
        }
Exemplo n.º 13
0
 public IActionResult OnGet(int?restaurantId)
 {
     if (restaurantId.HasValue)
     {
         Restaurant = _restaurantData.GetById(restaurantId.Value);
     }
     else
     {
         Restaurant = new RestaurantModel();
     }
     Cuisines = _htmlHelper.GetEnumSelectList <CuisineType>();
     if (Restaurant == null)
     {
         return(RedirectToPage("./NotFound"));
     }
     return(Page());
 }
Exemplo n.º 14
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            RestaurantModel = await _context.RestaurantModels.FindAsync(id);

            if (RestaurantModel != null)
            {
                _context.RestaurantModels.Remove(RestaurantModel);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 15
0
        public RestaurantModel GetByID(int id)
        {
            //throw new NotImplementedException();
            RestaurantModel  restaurantModel         = new RestaurantModel();
            DataAccessStatus dataAccesStatus         = new DataAccessStatus();
            bool             MatchingRestaurantFound = false;
            string           sql = "SELECT * FROM Restaurants WHERE RestaurantID = @RestaurantID";

            using (SQLiteConnection sqLiteConnection = new SQLiteConnection(_connectionString))
            {
                try
                {
                    sqLiteConnection.Open();
                    using (SQLiteCommand cmd = new SQLiteCommand(sql, sqLiteConnection))
                    {
                        cmd.CommandText = sql;
                        cmd.Prepare();
                        cmd.Parameters.Add(new SQLiteParameter("@RestaurantID", id));
                        using (SQLiteDataReader reader = cmd.ExecuteReader())
                        {
                            MatchingRestaurantFound = reader.HasRows;
                            while (reader.Read())
                            {
                                restaurantModel.RestaurantID      = Int32.Parse(reader["RestaurantID"].ToString());
                                restaurantModel.RestaurantName    = reader["RestaurantName"].ToString();
                                restaurantModel.RestaurantAddress = reader["RestaurantAddress"].ToString();
                            }
                        }
                        sqLiteConnection.Close();
                    }
                }
                catch (SQLiteException e)
                {
                    dataAccesStatus.setValues(status: "Error", operationSucceded: false, exceptionMessage: e.Message, customMessage: "Unable to get Restaurant Model from db", helpLink: e.HelpLink, errorCode: e.ErrorCode, stackTrace: e.StackTrace);
                    throw new DataAccessException(e.Message, e.InnerException, dataAccesStatus);
                }

                if (!MatchingRestaurantFound)
                {
                    dataAccesStatus.setValues(status: "Error", operationSucceded: false, exceptionMessage: "", customMessage: "Unable to find Restaurant Model in db", helpLink: "", errorCode: 0, stackTrace: "");
                    throw new DataAccessException(dataAccesStatus);
                }
                return(restaurantModel);
            }
        }
        public IActionResult Put(int id, [FromBody] RestaurantModel restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                restaurant.Id = id;
                _restaurantService.UpdateRestaurant(restaurant);
                return(Ok(restaurant));
            }
            catch (RestaurantNotFoundException)
            {
                return(NotFound());
            }
        }
Exemplo n.º 17
0
        public Operation <RestaurantModel> CreateRestaurant(RestaurantModel model)
        {
            return(Operation.Create(() =>
            {
                //model.Validate();
                var isExists = _context.Restaurants.Where(c => c.RestName == model.RestName).FirstOrDefault();
                if (isExists != null)
                {
                    throw new Exception("restaurant already exist");
                }

                var entity = model.Create(model);
                _context.Restaurants.Add(entity);
                _context.SaveChanges();

                return model;
            }));
        }
Exemplo n.º 18
0
        public void Edit(RestaurantModel model)
        {
            var restaurant = _restaurantRepository.Get(model.RestaurantId);

            if (model.Photo != null)
            {
                using (var br = new BinaryReader(model.Photo.OpenReadStream()))
                {
                    restaurant.Photo = br.ReadBytes((int)model.Photo.Length);
                }
            }

            restaurant.RestaurantName        = model.Name;
            restaurant.RestaurantDescription = model.Description;
            restaurant.RestaurantDescription = model.Description;
            restaurant.DeliveryTime          = model.DeliveryTime;
            _restaurantRepository.SaveChanges();
        }
Exemplo n.º 19
0
        public System.Web.Http.Results.OkNegotiatedContentResult <List <RestaurantModel> > GetRestaurantsByName(String restaurantName)
        {
            SqlDataReader reader       = null;
            SqlConnection myConnection = new SqlConnection();

            myConnection.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["DBConnection"];
            SqlCommand sqlCmd = new SqlCommand();

            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.CommandText = "spGetRestaurants_By_Name";
            sqlCmd.Connection  = myConnection;

            SqlParameter parameter = new SqlParameter();

            parameter.ParameterName = "@Restaurant_Name";
            parameter.SqlDbType     = SqlDbType.VarChar;
            parameter.Size          = 100;
            parameter.Direction     = ParameterDirection.Input;
            parameter.Value         = restaurantName;
            sqlCmd.Parameters.Add(parameter);

            myConnection.Open();
            reader = sqlCmd.ExecuteReader();

            List <RestaurantModel> restaurantList = new List <RestaurantModel>();
            RestaurantModel        restaurant     = null;

            while (reader.Read())
            {
                restaurant = new RestaurantModel();
                restaurant.RestaurantId       = Convert.ToInt32(reader.GetValue(0));
                restaurant.RestaurantName     = Convert.ToString(reader.GetValue(1));
                restaurant.Address            = Convert.ToString(reader.GetValue(2));
                restaurant.City               = Convert.ToString(reader.GetValue(3));
                restaurant.State              = Convert.ToString(reader.GetValue(4));
                restaurant.ZipCode            = Convert.ToString(reader.GetValue(5));
                restaurant.EmailAddress       = Convert.ToString(reader.GetValue(6));
                restaurant.RestaurantImageURL = Convert.ToString(reader.GetValue(7));
                restaurant.EndDate            = reader.IsDBNull(8) ? (DateTime?)null : (DateTime?)reader.GetDateTime(8);
                restaurantList.Add(restaurant);
            }
            myConnection.Close();
            return(Ok(content: restaurantList));
        }
Exemplo n.º 20
0
        public RestaurantModel Get(int id)
        {
            RestaurantModel model = new RestaurantModel();

            try
            {
                var result = restaurantBusiness.Get(id);

                model.IdRestaurant = result.IdRestaurant;
                model.NmRestaurant = result.NmRestaurant;
                model.ErrorSuccess = true;
            }
            catch (Exception ex)
            {
                model.ErrorSuccess   = false;
                model.ErrorNmMessage = ex.Message;
            }
            return(model);
        }
Exemplo n.º 21
0
        // GET: Diners
        public ActionResult Index(int?id)
        {
            RestaurantModel restaurantmodel = new RestaurantModel();

            restaurantmodel.ListOfFoodtypes = AllFoodTypes;


            if (id == null)
            {
                //Pakket samenvoegen zodat dit gebruiksklaar is...
                restaurantmodel.Restaurants = dinerrp.GetAllRestaurants();
            }
            else
            {
                int categorieId = id.GetValueOrDefault();
                restaurantmodel.Restaurants = dinerrp.GetRestaurants(categorieId);
            }
            return(View(restaurantmodel));
        }
Exemplo n.º 22
0
        public RestaurantModel Post([FromForm] int restaurantId, string restaurantName)
        {
            RestaurantModel model = new RestaurantModel();

            try
            {
                RestaurantEntity entity = new RestaurantEntity();
                entity.IdRestaurant = restaurantId;
                entity.NmRestaurant = restaurantName;
                restaurantBusiness.Create(entity);
                model.ErrorSuccess = true;
            }
            catch (Exception ex)
            {
                model.ErrorSuccess   = false;
                model.ErrorNmMessage = ex.Message;
            }
            return(model);
        }
Exemplo n.º 23
0
        public RestaurantModel MapRestaurant(Restaurant restaurant)
        {
            var mappedRestaurant = new RestaurantModel()
            {
                Id             = restaurant.Id,
                Name           = restaurant.Name,
                Details        = restaurant.Details,
                Contact        = restaurant.Contact,
                WeekendHours   = restaurant.WeekendHours,
                WeekdayHours   = restaurant.WeekdayHours,
                Address        = restaurant.Address,
                PhotoUrl       = restaurant.PhotoUrl,
                AverageBill    = restaurant.AverageBill,
                MaxPeopleCount = restaurant.MaxPeopleCount,
                Manager        = restaurant.Manager.FirstName + " " + restaurant.Manager.LastName
            };

            return(mappedRestaurant);
        }
Exemplo n.º 24
0
        public void ActionCreateRestaurantShould_CallMapper_WhenRestaurantWasCreated()
        {
            var model = new RestaurantModel()
            {
                Id             = Guid.NewGuid(),
                Name           = "Restaurant",
                Address        = "test",
                Contact        = "test",
                WeekdayHours   = "09:00 - 22:00",
                WeekendHours   = "09:00 - 22:00",
                PhotoUrl       = "test",
                MaxPeopleCount = 20,
                AverageBill    = 5,
                Details        = "test"
            };

            var result = controller.CreateRestaurant(model);

            mapperMock.Verify(m => m.MapRestaurant(restaurant), Times.Once);
        }
Exemplo n.º 25
0
        public void ActionEditRestaurantShould_CallMapper_WhenRestaurantIsUpdated()
        {
            var id    = Guid.NewGuid();
            var model = new RestaurantModel()
            {
                Name           = "Restaurant",
                Address        = "test",
                Contact        = "test",
                WeekdayHours   = "09:00 - 22:00",
                WeekendHours   = "09:00 - 22:00",
                PhotoUrl       = "test",
                MaxPeopleCount = 20,
                AverageBill    = 5,
                Details        = "test"
            };

            var result = controller.EditRestaurant(id, model);

            mapperMock.Verify(m => m.MapRestaurant(restaurant));
        }
Exemplo n.º 26
0
        public void ActionEditRestaurantShould_ReturnOkWithUpdatedRestaurant_WhenRestaurantIsUpdated()
        {
            var id    = Guid.NewGuid();
            var model = new RestaurantModel()
            {
                Name           = "Restaurant",
                Address        = "test",
                Contact        = "test",
                WeekdayHours   = "09:00 - 22:00",
                WeekendHours   = "09:00 - 22:00",
                PhotoUrl       = "test",
                MaxPeopleCount = 20,
                AverageBill    = 5,
                Details        = "test"
            };

            var result = controller.EditRestaurant(id, model);

            Assert.IsInstanceOf <OkNegotiatedContentResult <RestaurantModel> >(result);
        }
Exemplo n.º 27
0
        public void ActionCreateRestaurantShould_GetCurrentUserID_WhenCurrentUserIsManager()
        {
            var model = new RestaurantModel()
            {
                Id             = Guid.NewGuid(),
                Name           = "Restaurant",
                Address        = "test",
                Contact        = "test",
                WeekdayHours   = "09:00 - 22:00",
                WeekendHours   = "09:00 - 22:00",
                PhotoUrl       = "test",
                MaxPeopleCount = 20,
                AverageBill    = 5,
                Details        = "test"
            };

            var result = controller.CreateRestaurant(model);

            authProviderMock.Verify(ap => ap.CurrentUserID, Times.Once);
        }
Exemplo n.º 28
0
 public FileContentResult GetImagesRst(string id)
 {
     if (!string.IsNullOrEmpty(id))
     {
         RestaurantModel           rm   = new RestaurantModel();
         List <RestaurantAbstract> list = rm.getImageRst(id);
         if (list != null && list.Count > 0)
         {
             RestaurantAbstract info = list.First();
             if (info != null)
             {
                 if (info.Photo != null)
                 {
                     return(File(info.Photo, "jpg", "image_" + id + ".jpg"));
                 }
             }
         }
     }
     return(File(new byte[] { }, "jpg", "image_" + id + ".jpg"));
 }
Exemplo n.º 29
0
        public async Task <ActionResult> Edit(int id, RestaurantModel restaurant)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(restaurant));
            }

            if (restaurant.Image?.Length > 0)
            {
                using var ms = new MemoryStream();
                restaurant.Image.CopyTo(ms);
                var fileBytes = ms.ToArray();
                restaurant.ImageData = $"data:{MimeTypeMap.GetMimeType(Path.GetExtension(restaurant.Image.FileName))};base64,{Convert.ToBase64String(fileBytes)}";
            }

            restaurant.Id = id;
            var result = await this.apiCallHelper.Edit(restaurant);

            return(Validate <RestaurantDTO>(result, this.apiCallHelper, restaurant));
        }
Exemplo n.º 30
0
        public IActionResult Edit(RestaurantModel model)
        {
            try
            {
                if (model.RestaurantId > 0)
                {
                    _restaurantService.Edit(model);
                }
                else
                {
                    _restaurantService.Add(model);
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to load retaurant details");
                return(RedirectToAction("Edit", model.RestaurantId));
            }
        }