コード例 #1
0
        public ActionResult Edit([Bind(Prefix = "MaintenanceLog", Include = "Id,RoomId,BuildingId,BuildingName,Floor,RoomNumber,Description,Date,MaintenanceTypeId,MaintenanceType")] MaintenanceLogViewModel collection)
        {
            if (Session["AccessLevel"] == null || int.Parse(Session["AccessLevel"].ToString()) == 2 || int.Parse(Session["AccessLevel"].ToString()) == 3)
            {
                return(Redirect("~/NotAuthorized/Index"));
            }
            collection.RoomId            = _services.GetRoomId(collection.BuildingName, collection.Floor, collection.RoomNumber);
            collection.MaintenanceTypeId = _services.GetMaintenanceTypeByName(collection.MaintenanceType);
            if (ModelState.IsValid)
            {
                var pakage = new PackageMaintenanceLogViewModel()
                {
                    MaintenanceLog = collection
                };
                _services.PostChangesForEdit(pakage);
                return(RedirectToAction("Index"));
            }


            return(View(new PackageMaintenanceLogViewModel()
            {
                MaintenanceLog = collection,
                RoomsList = _services.InfoForMaintenaneLogCreateEdit().RoomsList,
                MaintenanceTypeList = _services.InfoForMaintenaneLogCreateEdit().MaintenanceTypeList
            }));
        }
コード例 #2
0
        public ActionResult Create([Bind(Prefix = "MaintenanceLog", Include = "Id,RoomId,BuildingId,BuildingName,Floor,RoomNumber,Description,Date,MaintenanceTypeId,MaintenanceType")] MaintenanceLogViewModel model)
        {
            if (Session["AccessLevel"] == null || int.Parse(Session["AccessLevel"].ToString()) == 2 || int.Parse(Session["AccessLevel"].ToString()) == 3)
            {
                return(Redirect("~/NotAuthorized/Index"));
            }
            model.RoomId            = _services.GetRoomId(model.BuildingName, model.Floor, model.RoomNumber);
            model.MaintenanceTypeId = _services.GetMaintenanceTypeByName(model.MaintenanceType);
            var returnModel = new PackageMaintenanceLogViewModel()
            {
                MaintenanceTypeList = _services.InfoForMaintenaneLogCreateEdit().MaintenanceTypeList,
                RoomsList           = _services.InfoForMaintenaneLogCreateEdit().RoomsList,
                Room           = new RoomViewModel(),
                MaintenanceLog = model
            };

            if (ModelState.IsValid)
            {
                _services.CreateNewMaintenanceLog(returnModel);
                return(RedirectToAction("Index"));
            }
            return(View(returnModel));
        }