public ActionResult Edit(Guid id) { var userId = User.Identity.GetUserName(); if (userRoleRepository.GetRoleByUserName(userId) != null && userRoleRepository.GetRoleByUserName(userId).IdUserType == "Admin") { var departmentItems = departmentRepository.GetAllDepartments(); if (departmentItems != null && departmentItems.Count != 0) { ViewBag.datadepartments = departmentItems; } var buildingItems = buildingRepository.GetAllOfficeBuildings(); if (buildingItems != null && buildingItems.Count != 0) { ViewBag.databuildings = buildingItems; } FloorsModel floorsModel = floorRepository.GetFloorById(id); return(View("EditFloor", floorsModel)); } else { return(RedirectToAction("Contact", "Home")); } }
public ActionResult Edit(Guid id, FormCollection collection) { try { var userId = User.Identity.GetUserName(); if (userRoleRepository.GetRoleByUserName(userId) != null && userRoleRepository.GetRoleByUserName(userId).IdUserType == "Admin") { // TODO: Add update logic here var alreadySetFloorLimit = 0; var departmentItems = departmentRepository.GetAllDepartments(); if (departmentItems != null && departmentItems.Count != 0) { ViewBag.datadepartments = departmentItems; } var buildingItems = buildingRepository.GetAllOfficeBuildings(); if (buildingItems != null && buildingItems.Count != 0) { ViewBag.databuildings = buildingItems; } FloorsModel floorsModel = new FloorsModel(); floorsModel.IdDepartment = Guid.Parse(Request.Form["Department"]); floorsModel.IdBuilding = Guid.Parse(Request.Form["Building"]); UpdateModel(floorsModel); var floors = floorRepository.GetFloorByDepartmentId(floorsModel.IdDepartment); foreach (FloorsModel floor in floors) { alreadySetFloorLimit = floor.BookableSeats + alreadySetFloorLimit; } alreadySetFloorLimit = alreadySetFloorLimit + floorsModel.BookableSeats; if (alreadySetFloorLimit <= departmentRepository.GetDepartmentById(floorsModel.IdDepartment).MaximumSeatsPerDepartment) { floorRepository.UpdateFloor(floorsModel); return(RedirectToAction("Index")); } else { return(RedirectToAction("IndexError_MaximumSurpassed")); } } else { return(RedirectToAction("Contact", "Home")); } } catch { return(View("EditFloor")); } }
public ActionResult FloorInsert(FloorsModel floormodel) { Floors floors = floormodel.ModelToEnity(); floors.IsActive = true; _servisceFloors.Insert(floors); return(RedirectToAction("FloorList")); }
public ActionResult Details(Guid id) { var userId = User.Identity.GetUserName(); if (userRoleRepository.GetRoleByUserName(userId) != null) { FloorsModel floorModel = floorRepository.GetFloorById(id); return(View("DetailsFloors", floorModel)); } else { return(RedirectToAction("Contact", "Home")); } }
public void UpdateFloor(FloorsModel floors) { Floor floorDb = dbContext.Floors.FirstOrDefault(x => x.IdFloor == floors.IdFloor); if (floorDb != null) { floorDb.IdFloor = floors.IdFloor; floorDb.Name = floors.Name; floorDb.IdDepartment = floors.IdDepartment; floorDb.IdBuilding = floors.IdBuilding; floorDb.BookableSeats = floors.BookableSeats; floorDb.FloorDescription = floors.FloorDescription; dbContext.SubmitChanges(); } }
public static Floors ModelToEnity(this FloorsModel model, bool virtualActive = false) { Floors entity = new Floors() { Name = model.Name, Id = model.Id, IsActive = model.IsActive }; if (virtualActive) { entity.BlockFloors = model.BlockFloors; } return(entity); }
private FloorsModel MapDbObjectToModel(Floor dbFloor) { FloorsModel floor = new FloorsModel(); if (dbFloor != null) { floor.IdFloor = dbFloor.IdFloor; floor.Name = dbFloor.Name; floor.IdDepartment = dbFloor.IdDepartment; floor.IdBuilding = dbFloor.IdBuilding; floor.BookableSeats = dbFloor.BookableSeats; floor.FloorDescription = dbFloor.FloorDescription; return(floor); } return(null); }
private Floor MapModelToDbObject(FloorsModel floor) { Floor floorDb = new Floor(); if (floor != null) { floorDb.IdFloor = floor.IdFloor; floorDb.Name = floor.Name; floorDb.IdDepartment = floor.IdDepartment; floorDb.IdBuilding = floor.IdBuilding; floorDb.BookableSeats = floor.BookableSeats; floorDb.FloorDescription = floor.FloorDescription; return(floorDb); } return(null); }
public bool IsDuplicateFloor(FloorsModel floor) { var floorByBuildingId = GetFloorByBuildingId(floor.IdBuilding); if (floorByBuildingId == null) { return(false); } else { if (floorByBuildingId.IdDepartment == floor.IdDepartment) { return(true); } else { return(false); } } }
public static FloorsModel EntityToModel(this Floors entity, bool virtualActive = false) { try { FloorsModel model = new FloorsModel() { Name = entity.Name, IsActive = entity.IsActive, Id = entity.Id }; if (virtualActive) { model.BlockFloors = entity.BlockFloors; } return(model); } catch (Exception) { return(new FloorsModel()); } }
public void InsertFloorBuilding(FloorsModel floor) { floor.IdFloor = Guid.NewGuid(); dbContext.Floors.InsertOnSubmit(MapModelToDbObject(floor)); dbContext.SubmitChanges(); }
public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here var userId = User.Identity.GetUserName(); if (userRoleRepository.GetRoleByUserName(userId) != null && userRoleRepository.GetRoleByUserName(userId).IdUserType == "Admin") { var alreadySetFloorLimit = 0; var departmentItems = departmentRepository.GetAllDepartments(); if (departmentItems != null && departmentItems.Count != 0) { ViewBag.datadepartments = departmentItems; } var buildingItems = buildingRepository.GetAllOfficeBuildings(); if (buildingItems != null && buildingItems.Count != 0) { ViewBag.databuildings = buildingItems; } FloorsModel floorModel = new FloorsModel(); floorModel.IdDepartment = Guid.Parse(Request.Form["Department"]); floorModel.IdBuilding = Guid.Parse(Request.Form["Building"]); UpdateModel(floorModel); //Check if allowed seats department limit is surpassed //First calculate how many seats you would have with this additional entry var floors = floorRepository.GetFloorByDepartmentId(floorModel.IdDepartment); foreach (FloorsModel floor in floors) { alreadySetFloorLimit = floor.BookableSeats + alreadySetFloorLimit; } alreadySetFloorLimit = alreadySetFloorLimit + floorModel.BookableSeats; //Check which is the maximum allowed overall space at department level if (alreadySetFloorLimit <= departmentRepository.GetDepartmentById(floorModel.IdDepartment).MaximumSeatsPerDepartment) { if (floorRepository.IsDuplicateFloor(floorModel) == false) { floorRepository.InsertFloorBuilding(floorModel); return(RedirectToAction("Index")); } else { return(RedirectToAction("IndexError")); } } else { return(RedirectToAction("IndexError_MaximumSurpassed")); } } else { return(RedirectToAction("Contact", "Home")); } } catch { return(View("CreateFloor")); } }