コード例 #1
0
        /// <summary>
        /// This action will be used to send a new/eddited establishment to the DB
        /// </summary>
        /// <param name="establishmentName"></param>
        /// <param name="establishmentID"></param>
        /// <returns></returns>
        public ActionResult AddEditEstablishment(string establishmentName, int establishmentID)
        {
            var db = new ExpenseDb();

            if (establishmentID <= 0) /// we add a new est to the DB
            {
                var establishment = new Establishment { EstablishmentName = establishmentName };
                db.EstablishmentTBL.Add(establishment);
                db.SaveChanges();

            }
            else // we edit the Est on the DB
            {
                db.EstablishmentTBL.Where(e => e.Id == establishmentID).FirstOrDefault().EstablishmentName = establishmentName;
                db.SaveChanges();

            }

            // here we return an updated list of the Establishments
            EstablishmentViewModel model = GetEstablishments(db);

            return PartialView("_EstablishmentTable", model);
        }
コード例 #2
0
        ///////------------------------------------------- Establishment Actions : 
        public ActionResult AddEstablishment(string establishmentName)
        {
            // in this instance we dont have Access to the Id's so we will only compare the stirngs client side
            // so we will always be creating a new Establishment

            var db = new ExpenseDb();

                var establishment = new Establishment { EstablishmentName = establishmentName };
                db.EstablishmentTBL.Add(establishment);

                db.SaveChanges();

            // here we return an updated list of the Establishments
            var establishments = GetEstablishments(db);

            var viewModel = new ExpenseDetailsViewModel();
            viewModel.Establishments = establishments;

            return PartialView("_EstablishmentTxt",viewModel);
        }