/// <summary> /// Description: This method calls a method in DAL to update a restaurant with new values /// </summary> /// <param name="iRestaurant">Restaurant to be updated</param> /// <returns>If successfully updated, return true. Otherwise, false</returns> public bool UpdateRestaurantByRestaurantID(RestaurantDBO iRestaurant) { // Instantiate DAL Object RestaurantDAL lRestaurantDAL = new RestaurantDAL(); // Get bool result bool lResult = lRestaurantDAL.UpdateRestaurantByRestaurantID(iRestaurant); return(lResult); }
/// <summary> /// Description: This method calls a method in DAL to insert data about a restaurant into database /// </summary> /// <param name="iRestaurant">Restaurant object with data</param> /// <returns>A unique restaurant id</returns> public int CreateRestaurant(RestaurantDBO iRestaurant) { // Instantiate DAL Object RestaurantDAL lRestaurantDAL = new RestaurantDAL(); // Get Inserted.RestaurantIDPK as return value int lRestaurantIDPK = lRestaurantDAL.CreateRestaurant(iRestaurant); return(lRestaurantIDPK); }
/// <summary> /// Description: This method calls a method in DAL to retrieve data about a restaurant /// </summary> /// <param name="id">A unique restaurant id</param> /// <returns>Restaurant object with data</returns> public RestaurantDBO FindRestaurantByRestaurantID(int id) { // Instantiate DAL Object RestaurantDAL lRestaurantDAL = new RestaurantDAL(); // Get the restaurant RestaurantDBO lRestaurant = lRestaurantDAL.FindRestaurantByRestaurantID(id); return(lRestaurant); }
public ActionResult RestaurantUpdate(Restaurant iRestaurant) { if (ModelState.IsValid) { // validation for price if (!Decimal.TryParse(iRestaurant.SandwichPrice.ToString(), out decimal price)) { return(View(iRestaurant)); } // Instantiate objects RestaurantBLL lRestaurantBLL = new RestaurantBLL(); RestaurantMapper lRestaurantMapper = new RestaurantMapper(); // Map Model to DB object RestaurantDBO lRestaurantDBO = lRestaurantMapper.MapModelToDBO(iRestaurant); // get result after update bool lResult = lRestaurantBLL.UpdateRestaurantByRestaurantID(lRestaurantDBO); if (lResult) { // success TempData["msg"] = "<script>alert('Successfully Updated!')</script>"; return(RedirectToAction("RestaurantProfile", "Restaurant", new { id = lRestaurantDBO.RestaurantIDPK })); } else { // failure TempData["msg"] = "<script>alert('Error occured while processing your request. Please try later.')</script>"; } } else { // model state not valid TempData["msg"] = "<script>alert('Please Fill all Required Fields.')</script>"; } // Add days to the list iRestaurant.DayList = new List <string>(); iRestaurant.DayList.Add("Monday"); iRestaurant.DayList.Add("Tuesday"); iRestaurant.DayList.Add("Wednesday"); iRestaurant.DayList.Add("Thursday"); iRestaurant.DayList.Add("Friday"); iRestaurant.DayList.Add("Saturday"); iRestaurant.DayList.Add("Sunday"); return(View(iRestaurant)); }
/// <summary> /// Description: This method maps Restaurant Model object to Restaurant Database object /// </summary> /// <param name="iRestaurant">Restaurant Model object</param> /// <returns>Restaurant Database object</returns> public RestaurantDBO MapModelToDBO(Restaurant iRestaurant) { RestaurantDBO lRestaurantDBO = new RestaurantDBO(); // set values lRestaurantDBO.RestaurantIDPK = iRestaurant.RestaurantIDPK; lRestaurantDBO.RestaurantName = iRestaurant.RestaurantName; lRestaurantDBO.DayofWeek = iRestaurant.DayofWeek; lRestaurantDBO.Contact = iRestaurant.Contact; lRestaurantDBO.Email = iRestaurant.Email; lRestaurantDBO.Notice = iRestaurant.Notice; lRestaurantDBO.IsActive = iRestaurant.IsActive; lRestaurantDBO.IsSandwichRestaurant = iRestaurant.IsSandwichRestaurant; lRestaurantDBO.SandwichPrice = iRestaurant.SandwichPrice; return(lRestaurantDBO); }
public ActionResult RestaurantRegister(Restaurant iRestaurant) { if (ModelState.IsValid) { // Map Models.Restaurant to db objects RestaurantMapper lRestaurantMapper = new RestaurantMapper(); RestaurantDBO lRestaurantDBO = lRestaurantMapper.MapModelToDBO(iRestaurant); // insert mapped object into database RestaurantBLL lRestaurantBLL = new RestaurantBLL(); int lRestaurantIDPK = lRestaurantBLL.CreateRestaurant(lRestaurantDBO); if (lRestaurantIDPK > 0) { // success ViewBag.msg = "<script>alert('Registered Successfully');</script>"; return(RedirectToAction("RestaurantList", "Restaurant")); } else { // failure ViewBag.msg = "<script>alert('Registeration Failed');</script>"; } } else { //not valid model state ViewBag.msg = "<script>alert('Not Valid Inputs');</script>"; } // re-populate days to the list in case of failure iRestaurant.DayList = new List <string>(); iRestaurant.DayList.Add("Monday"); iRestaurant.DayList.Add("Tuesday"); iRestaurant.DayList.Add("Wednesday"); iRestaurant.DayList.Add("Thursday"); iRestaurant.DayList.Add("Friday"); iRestaurant.DayList.Add("Saturday"); iRestaurant.DayList.Add("Sunday"); return(View(iRestaurant)); }
/// <summary> /// Description: This method maps Restaurant database object to Restaurant Model object /// </summary> /// <param name="iRestaurantDBO">Restaurant database object with data</param> /// <returns>Restaurant Model object</returns> public Restaurant MapDBOToModel(RestaurantDBO iRestaurantDBO) { Restaurant lRestaurant = new Restaurant(); // set values lRestaurant.RestaurantIDPK = iRestaurantDBO.RestaurantIDPK; lRestaurant.RestaurantName = iRestaurantDBO.RestaurantName; lRestaurant.DayofWeek = iRestaurantDBO.DayofWeek; lRestaurant.Contact = iRestaurantDBO.Contact; lRestaurant.Email = iRestaurantDBO.Email; lRestaurant.Notice = iRestaurantDBO.Notice; lRestaurant.DateCreated = iRestaurantDBO.DateCreated; lRestaurant.DateModified = iRestaurantDBO.DateModified; lRestaurant.IsActive = iRestaurantDBO.IsActive; lRestaurant.IsSandwichRestaurant = iRestaurantDBO.IsSandwichRestaurant; lRestaurant.SandwichPrice = iRestaurantDBO.SandwichPrice; return(lRestaurant); }
public ActionResult RestaurantUpdate(int id) { // Instantiate objects RestaurantBLL lRestaurantBLL = new RestaurantBLL(); RestaurantMapper lRestaurantMapper = new RestaurantMapper(); // Get info about the restaurant RestaurantDBO lRestaurantDBO = lRestaurantBLL.FindRestaurantByRestaurantID(id); // map DB object to model Restaurant lRestaurant = lRestaurantMapper.MapDBOToModel(lRestaurantDBO); // Add days to the list lRestaurant.DayList = new List <string>(); lRestaurant.DayList.Add("Monday"); lRestaurant.DayList.Add("Tuesday"); lRestaurant.DayList.Add("Wednesday"); lRestaurant.DayList.Add("Thursday"); lRestaurant.DayList.Add("Friday"); lRestaurant.DayList.Add("Saturday"); lRestaurant.DayList.Add("Sunday"); return(View(lRestaurant)); }