public ActionResult Edit(RoommateModel model)
 {
     if (ModelState.IsValid)
     {
         UpdateRoommate(model.RoommateId, model.FirstName, model.LastName);
     }
     return(RedirectToAction("ViewHousehold"));
 }
예제 #2
0
        public static void DeleteRoommate(int id)
        {
            RoommateModel roommate = new RoommateModel
            {
                RoommateId = id,
            };

            var sql = $"sp_RemoveRoommate '{id}'";

            SqlDataAccess.SaveData <RoommateModel>(sql, roommate);
        }
        public ActionResult Delete(int id)
        {
            var           data  = GetRoommateById(id);
            RoommateModel model = new RoommateModel
            {
                RoommateId     = data.RoommateId,
                FirstName      = data.FirstName,
                LastName       = data.LastName,
                MonthlyPayment = data.MonthlyPayment
            };

            return(View(model));
        }
예제 #4
0
        public static void UpdateRoommate(int id, string firstName, string lastName)
        {
            //TODO create data to send
            RoommateModel data = new RoommateModel
            {
                FirstName      = firstName,
                LastName       = lastName,
                MonthlyPayment = (decimal)CalculatePayment()
            };
            string sql = $"sp_UpdateRoommate '{id}', '{firstName}', '{lastName}'";

            SqlDataAccess.SaveData <RoommateModel>(sql, data);
        }
        public ActionResult Join(RoommateModel model)
        {
            if (ModelState.IsValid)
            {
                int recordsCreated = CreateRoommate(
                    model.FirstName,
                    model.LastName,
                    model.MonthlyPayment);
                UpdatePayments(); //TODO dont hard code this
                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public ActionResult Edit(int roommateId)
        {
            var data = GetRoommateById(roommateId);
            //Todo should be mapping this to datalibrary model
            RoommateModel r = new RoommateModel
            {
                RoommateId     = data.RoommateId,
                FirstName      = data.FirstName,
                LastName       = data.LastName,
                MonthlyPayment = data.MonthlyPayment
            };

            return(View(r));
        }
        public ActionResult Delete(RoommateModel model)
        {
            //todo why is this not working like the bill delete does?

            //if (ModelState.IsValid)
            //{
            //Todo should be mapping this to datalibrary model
            DeleteRoommate(model.RoommateId);
            UpdatePayments();
            return(RedirectToAction("ViewHousehold"));

            //}
            return(View());
        }
예제 #8
0
        public static int CreateRoommate(string firstName, string lastName, decimal payment)
        {
            RoommateModel data = new RoommateModel
            {
                FirstName      = firstName,
                LastName       = lastName,
                MonthlyPayment = (decimal)CalculatePayment()
            };
            //string sql = @"insert into dbo.Roommates (FirstName, LastName)
            //                Values(@FirstName, @LastName);";


            string sql = $"sp_AddRoommate '{data.FirstName}','{data.LastName}', '{data.MonthlyPayment}'";

            return(SqlDataAccess.SaveData <RoommateModel>(sql, data));
        }
예제 #9
0
        public static RoommateModel GetRoommateById(int roommateId)
        {
            string        sql    = $"sp_GetRoommateById '{roommateId}'";
            var           data   = SqlDataAccess.LoadData <RoommateModel>(sql);
            RoommateModel result = new RoommateModel();

            foreach (var item in data)
            {
                result = new RoommateModel
                {
                    RoommateId     = item.RoommateId,
                    FirstName      = item.FirstName,
                    LastName       = item.LastName,
                    MonthlyPayment = item.MonthlyPayment
                };
            }
            return(result);
        }