Ejemplo n.º 1
0
 // GET: AddAsset
 public ActionResult AddAsset()
 {
     return(View(new AddAssetViewModel
     {
         AssetModels = db.AssetModelDropdown(),
         Rooms = db.RoomDropdown(),
     }));
 }
Ejemplo n.º 2
0
 //GET: CreateLoan
 public ActionResult CreateLoan(int id)
 {
     return(View(new CreateLoanViewModel
     {
         AssetId = id,
         AssetName = db.Assets.Find(id).Name,
         Rooms = db.RoomDropdown(),
         Hours = GenerateHours(),
     }));
 }
Ejemplo n.º 3
0
 public SearchViewModel()
 {
     //SelectedPositionId = -1;
     //Positions = db.UserPositionDropdown();
     SelectedRoomId = -1;
     Rooms          = db.RoomDropdown();
 }
Ejemplo n.º 4
0
 public CreateUserViewModel()
 {
     SelectedPositionId = -1;
     SelectedRoomId     = -1;
     Positions          = db.UserPositionDropdown();
     Rooms = db.RoomDropdown();
 }
Ejemplo n.º 5
0
        public EditUserViewModel(string id)
        {
            var user = db.Users.Find(id);

            Id                 = user.Id;
            FirstName          = user.FirstName;
            LastName           = user.LastName;
            Email              = user.Email;
            IsAdmin            = user.IsAdmin;
            SelectedPositionId = user.UserPositionId.HasValue ? user.UserPositionId.Value : -1;
            SelectedRoomId     = user.RoomId.HasValue ? user.RoomId.Value : -1;
            Rooms              = db.RoomDropdown();
            Positions          = db.UserPositionDropdown();
        }
Ejemplo n.º 6
0
        public ActionResult EditUser(EditUserViewModel vm)
        {
            var Success = false;
            var Message = "";

            var firstNameValidation = Models.User.Validator.ValidateFirstName(vm.FirstName);

            if (firstNameValidation != null)
            {
                ModelState.AddModelError("FirstName", firstNameValidation);
            }

            var lastNameValidation = Models.User.Validator.ValidateLastName(vm.LastName);

            if (lastNameValidation != null)
            {
                ModelState.AddModelError("LastName", lastNameValidation);
            }

            var emailValidation = Models.User.Validator.ValidateEmail(vm.Id, vm.Email);

            if (emailValidation != null)
            {
                ModelState.AddModelError("Email", emailValidation);
            }

            var positionValidation = Models.User.Validator.ValidatePosition(vm.SelectedPositionId);

            if (positionValidation != null)
            {
                ModelState.AddModelError("SelectedPositionId", positionValidation);
            }

            var roomValidation = Models.User.Validator.ValidateRoom(vm.SelectedRoomId);

            if (roomValidation != null)
            {
                ModelState.AddModelError("SelectedRoomId", roomValidation);
            }

            if (ModelState.IsValid)
            {
                var user = db.Users.Find(vm.Id);

                user.FirstName      = vm.FirstName;
                user.LastName       = vm.LastName;
                user.Email          = user.UserName = vm.Email;
                user.IsAdmin        = vm.IsAdmin;
                user.RoomId         = vm.SelectedRoomId;
                user.UserPositionId = vm.SelectedPositionId;

                try
                {
                    db.SaveChanges();
                    Success = true;
                    Message = Models.User.SAVE_SUCCESS;
                }
                catch (Exception)
                {
                    Message = Models.User.SAVE_FAIL;
                }

                return(Json(new { Success, Message }));
            }

            vm.Rooms     = db.RoomDropdown();
            vm.Positions = db.UserPositionDropdown();
            return(PartialView("_EditUser", vm));
        }
Ejemplo n.º 7
0
 public ChangeLocationViewModel()
 {
     SelectedRoomId = -1;
     Rooms          = db.RoomDropdown();
 }