Пример #1
0
        public ActionResult AddRoom(int?Id)
        {
            UserModel session = (UserModel)Session["CurrentUser"];

            if (session == null || !session.IsAdmin)
            {
                return(RedirectToAction("Index", "Login"));
            }
            HostelRoom model = new HostelRoom();

            if (Id > 0)
            {
                model = (from room in entity.HostelRooms where room.Id == Id select room).FirstOrDefault();
            }
            return(View(model));
        }
Пример #2
0
        public JsonResult SaveRoom(HostelRoom model)
        {
            AjaxModel result = new AjaxModel();

            try
            {
                UserModel session = (UserModel)Session["CurrentUser"];
                if (model == null)
                {
                    result.Success = false;
                    result.Message = "Internal Server Error.";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                var info = (from room in entity.HostelRooms where room.RoomNo == model.RoomNo select room).FirstOrDefault();

                if (info != null && model.Id == 0)
                {
                    result.Success = false;
                    result.Message = "Room Number already exist.";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                result.Success = true;
                result.Message = model.Id == 0 ? "New Room Added Succesfully." : "Room Updated Successfully.";
                if (model.Id == 0)
                {
                    helper.ManageLogs(session.UserId, "New room added by " + session.FirstName + " " + session.LastName);
                }
                else
                {
                    info.RoomChangres = model.RoomChangres;
                    info.Description  = model.Description;
                    info.NoOfBeds     = model.NoOfBeds;
                    info.Floor        = model.Floor;
                    helper.ManageLogs(session.UserId, "Room Number " + model.RoomNo + " updated by " + session.FirstName + " " + session.LastName);
                }
                entity.HostelRooms.Add(model);
                entity.SaveChanges();
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }