Esempio n. 1
0
 public ActionResult Create([Bind(Include = "ID,Name")] AreaModel area)
 {
     if (ModelState.IsValid)
     {
         try
         {
             // Checking if already exist an area with same name (case insensitive)
             if (areaData.CheckIfAlreadyExist(area.Name) == false)
             {
                 IAreaModel model = area;
                 areaData.Create(model);
                 return(RedirectToAction("Index"));
             }
             else
             {
                 log.Info("The user tried to add an area that already existed");
                 return(View("AlreadyExists"));
             }
         }
         catch (Exception ex)
         {
             log.Error("Could't create a new area in the Database", ex);
             return(View("ErrorRetriveData"));
         }
     }
     else
     {
         log.Error("The model state of the area is invalid");
         return(View("WrongData"));
     }
 }
Esempio n. 2
0
        // Form to edit an area
        public ActionResult Edit(int?id)
        {
            if (id != null)
            {
                try
                {
                    IAreaModel area = areaData.FindById((int)id);

                    if (area == null)
                    {
                        log.Error("Could't find an area in the Database - return null");
                        return(View("ErrorEdit"));
                    }
                    return(View(area));
                }

                catch (Exception ex)
                {
                    log.Error("Could't find an area in the Database", ex);
                    return(View("ErrorRetriveData"));
                }
            }
            else
            {
                log.Error("The area ID was null while trying to edit");
                return(View("ErrorEdit"));
            }
        }
Esempio n. 3
0
 // PUT: api/Areas/5
 public void Put([FromBody] AreaModel area)
 {
     if (ModelState.IsValid)
     {
         if (areaData.CheckIfAlreadyExist(area.Name) == false)
         {
             IAreaModel model = area;
             areaData.Update(model);
         }
     }
 }
Esempio n. 4
0
        // Asks for confirmation in order to delete an area from the database
        public ActionResult Delete(int?id)
        {
            if (id != null)
            {
                try
                {
                    IAreaModel area = areaData.FindById((int)id);

                    if (area == null)
                    {
                        log.Error("Could't find an area in the Database - return null");
                        return(View("ErrorDelete"));
                    }

                    // It gets the number of tables in selected area in order to display to the user
                    List <ITableModel> tables = tableData.GetBySubGroup((int)id);
                    area.NumberOfTables = tables.Count();

                    foreach (ITableModel table in tables)
                    {
                        if (table.Occupied)
                        {
                            log.Info("The user tried to delete an area with opened tables");
                            return(View("OpenedTable"));
                        }
                    }

                    return(View(area));
                }

                catch (Exception ex)
                {
                    log.Error("Could't find an area in the Database", ex);
                    return(View("ErrorRetriveData"));
                }
            }
            else
            {
                log.Error("The area ID was null while trying to delete");
                return(View("ErrorDelete"));
            }
        }
Esempio n. 5
0
 public TableModel(IAreaModel area, List <ISoldProductModel> soldProducts)
 {
     Area         = area;
     SoldProducts = soldProducts;
 }