Example #1
0
        public JsonResult SaveRoomAllocationInfo(RoomAllocation rAllocation)
        {
            string result = "";

            //try
            //{
            if (ModelState.IsValid)
            {
                result = CheckTimeOverlapOrNot(rAllocation);
                if (result == "NotOverlap")
                {
                    RoomAllocation allocation = new RoomAllocation();
                    allocation.CourseId      = rAllocation.CourseId;
                    allocation.RoomId        = rAllocation.RoomId;
                    allocation.DayId         = rAllocation.DayId;
                    allocation.StarTime      = rAllocation.StarTime;
                    allocation.EndTime       = rAllocation.EndTime;
                    allocation.IsUnAllocated = false;
                    db.RoomAllocations.Add(allocation);
                    db.SaveChanges();
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public string CheckTimeOverlapOrNot(RoomAllocation rAllocation)
        {
            var allocatedRoomByDay = db.RoomAllocations.Where(x => x.RoomId == rAllocation.RoomId && x.DayId == rAllocation.DayId && x.IsUnAllocated == false).ToList();

            if (allocatedRoomByDay.Count > 0)
            {
                foreach (var aTime in allocatedRoomByDay)
                {
                    if (aTime.StarTime.TimeOfDay < rAllocation.EndTime.TimeOfDay && rAllocation.StarTime.TimeOfDay < aTime.EndTime.TimeOfDay)
                    {
                        string overlap = "";
                        var    course  = db.Courses.FirstOrDefault(x => x.Id == aTime.CourseId);
                        var    roomNo  = db.RoomInfos.FirstOrDefault(x => x.Id == aTime.RoomId);
                        var    day     = db.Days.FirstOrDefault(x => x.Id == aTime.DayId);
                        if (roomNo != null && course != null && day != null)
                        {
                            overlap = "Overlapping Schedule! Try Another ): " + "Coure : " + course.Name + "," + " R. No : " + roomNo.RoomNo + "," + " Day : " +
                                      day.DayName + ", " + aTime.StarTime.ToString("h:mm tt") + " - " + aTime.EndTime.ToString("h:mm tt");
                        }
                        return(overlap);
                    }
                }
            }
            return("NotOverlap");
        }
Example #3
0
        public int IsRoomAllocated(RoomAllocation roomAllocation)
        {
            SqlConnection connection = new SqlConnection(connectionString);
            //string query = "SELECT * FROM RoomAllocation where RoomId='" + roomAllocation.RoomId + "'and DayId='" + roomAllocation.DayId + "'and (FromTime <'" + roomAllocation.ToTime.ToString("hh:mm") + "' and '"+roomAllocation.FromTime.ToString("hh:mm")+"'< ToTime)  and FromTimeSelected='" + roomAllocation.FromTimeSelected + "' and ToTimeSelected='" + roomAllocation.ToTimeSelected + "' ";
            string     query   = "SELECT * FROM RoomAllocation where RoomId='" + roomAllocation.RoomId + "'and DayId='" + roomAllocation.DayId + "'and (FromTime <'" + roomAllocation.ToTime.ToString("hh:mm tt") + "' and '" + roomAllocation.FromTime.ToString("hh:mm tt") + "'< ToTime) ";
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            int status = -1;

            List <int>    roomAllocationId = new List <int>();
            SqlDataReader reader           = command.ExecuteReader();

            if (reader.HasRows)
            {
                RoomAllocation allocation = new RoomAllocation();
                while (reader.Read())

                {
                    status = (int)reader["RoomAllocationStatus"];
                    allocation.RoomAllocationId = (int)reader["RoomAllocationId"];

                    roomAllocationId.Add(allocation.RoomAllocationId);
                }
            }
            reader.Close();
            foreach (int id in roomAllocationId)
            {
                command.CommandText = "Update RoomAllocation set  RoomAllocationStatus=" + 1 + " where RoomAllocationId='" + id + "'";
                command.ExecuteNonQuery();
            }

            connection.Close();
            return(status);
        }
        public ActionResult AllocateRoom([Bind(Include = "Id,DepartmentId,CourseId,RoomId,DayId,StartTime,EndTime")] RoomAllocation roomallocation)
        {
            if (!roomManager.Overlaping(roomallocation.RoomId, roomallocation.DayId, roomallocation.StartTime,
                                        roomallocation.EndTime).Item1)
            {
                if (ModelState.IsValid)
                {
                    db.RoomAllocations.Add(roomallocation);
                    db.SaveChanges();
                    ViewBag.SuccessMessage = "New Schedule Saved Successfully!";
                    //return RedirectToAction("Index");
                }
            }
            else
            {
                ViewBag.FailMessage = roomManager.Overlaping(roomallocation.RoomId, roomallocation.DayId, roomallocation.StartTime,
                                                             roomallocation.EndTime).Item2;
            }

            //ViewBag.CourseId = new SelectList(db.Courses, "Id", "CourseCode", roomallocation.CourseId);
            ViewBag.DayId        = new SelectList(db.Days, "Id", "Name");
            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DeptCode", roomallocation.DepartmentId);
            ViewBag.RoomId       = new SelectList(db.Rooms, "Id", "RoomNo", roomallocation.RoomId);
            return(View());
        }
Example #5
0
        public JsonResult SaveRoomSchedule(RoomAllocation roomAllocation)
        {
            var scheduleList = db.RoomAllocations.Where(t => t.RoomId == roomAllocation.RoomId && t.DayId == roomAllocation.DayId && t.Status == "Allocated").ToList();

            if (scheduleList.Count == 0)
            {
                roomAllocation.Status = "Allocated";
                db.RoomAllocations.Add(roomAllocation);
                db.SaveChanges();
                return(Json(true));
            }
            else
            {
                bool state = false;
                foreach (var allocation in scheduleList)
                {
                    if ((roomAllocation.StartTime >= allocation.StartTime && roomAllocation.StartTime < allocation.EndTime) ||
                        (roomAllocation.EndTime > allocation.StartTime && roomAllocation.EndTime <= allocation.EndTime) && roomAllocation.Status == "Allocated")
                    {
                        state = true;
                    }
                }
                if (state == false)
                {
                    roomAllocation.Status = "Allocated";
                    db.RoomAllocations.Add(roomAllocation);
                    db.SaveChanges();
                    return(Json(true));
                }
                else
                {
                    return(Json(false));
                }
            }
        }
        public void Allocate(RoomAllocation aRoomAllocation)
        {
            string query = "INSERT INTO RoomAllocation (RoomId, CourseId, DayId, StartTime, EndTime, IsCurrent) VALUES (@roomId, @courseId, @dayId, @startTime, @endTime, @isCurrent)";

            using (connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.Clear();
                    command.Parameters.Add("roomId", sqlDbType: SqlDbType.Int);
                    command.Parameters["roomId"].Value = aRoomAllocation.RoomId;

                    command.Parameters.Add("courseId", sqlDbType: SqlDbType.Int);
                    command.Parameters["courseId"].Value = aRoomAllocation.CourseId;

                    command.Parameters.Add("dayId", sqlDbType: SqlDbType.Int);
                    command.Parameters["dayId"].Value = aRoomAllocation.DayId;

                    command.Parameters.Add("startTime", sqlDbType: SqlDbType.Time);
                    command.Parameters["startTime"].Value = aRoomAllocation.StartTime.TimeOfDay;

                    command.Parameters.Add("endTime", sqlDbType: SqlDbType.Time);
                    command.Parameters["endTime"].Value = aRoomAllocation.EndTime.TimeOfDay;

                    command.Parameters.Add("isCurrent", sqlDbType: SqlDbType.Bit);
                    command.Parameters["isCurrent"].Value = aRoomAllocation.IsCurrent;

                    connection.Open();
                    command.ExecuteNonQuery();
                }
        }
        public ActionResult AllocateClassRoom(string CourseCode, string RoomNo, string Day, string FromTime, string ToTime)
        {
            int affectedRow = 0;

            if (CourseCode != null)
            {
                RoomAllocation prevAllocation = GetAllocationInfo(CourseCode);
                if (prevAllocation.Day != Day || NoTimeOverlap(FromTime, ToTime, prevAllocation) == false)
                {
                    newDatabaseGateway.Command.CommandText = "INSERT INTO ROOM_SCHEDULE VALUES('" + CourseCode + "','" + RoomNo + "','" + Day + "','" + FromTime + "','" + ToTime + "','True');";
                    newDatabaseGateway.Connection.Open();
                    affectedRow = newDatabaseGateway.Command.ExecuteNonQuery();
                    newDatabaseGateway.Connection.Close();
                }
                if (affectedRow == 0)
                {
                    ViewBag.message = "Error Found";
                }
                else
                {
                    ViewBag.message = "Successfully Saved!!!!!";
                }
            }
            ViewBag.deptList = LoadDeptDropBox();
            ViewBag.rooms    = GetAllRooms();
            ViewBag.days     = GetAllDay();
            return(View());
        }
        public ActionResponse Allocate(RoomAllocation aRoomAllocation)
        {
            ActionResponse response = new ActionResponse();

            try
            {
                int compare = DateTime.Compare(aRoomAllocation.StartTime, aRoomAllocation.EndTime);
                if (compare > 0)
                {
                    response.Class   = "danger";
                    response.Message = "End Time [" + aRoomAllocation.EndTime.ToString("hh:mm tt") + "] must be grater than Start Time [" + aRoomAllocation.StartTime.ToString("hh:mm tt") + "].";
                    return(response);
                }
                bool isOverlap = aClassroomGateway.IsOverlap(aRoomAllocation);
                if (isOverlap)
                {
                    response.Class   = "danger";
                    response.Message = "Overlapping problem: Another class is allocated with this schedule.";
                    return(response);
                }

                aClassroomGateway.Allocate(aRoomAllocation);
                response.Class   = "success";
                response.Message = "Room Allocated successfully.";
            }
            catch (SqlException ex)
            {
                response.Class   = "warning";
                response.Message = ex.Message;
            }
            return(response);
        }
        public bool IsOverlap(RoomAllocation aRoomAllocation)
        {
            string query = "SELECT * FROM RoomAllocation WHERE RoomId=@roomId AND DayId=@dayId AND ( ( StartTime > @startTime AND StartTime < @endTime ) OR ( EndTime > @startTime AND EndTime < @endTime ) ) AND IsCurrent=1";

            using (connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.Clear();
                    command.Parameters.Add("roomId", sqlDbType: SqlDbType.Int);
                    command.Parameters["roomId"].Value = aRoomAllocation.RoomId;

                    command.Parameters.Add("dayId", sqlDbType: SqlDbType.Int);
                    command.Parameters["dayId"].Value = aRoomAllocation.DayId;

                    command.Parameters.Add("startTime", sqlDbType: SqlDbType.Time);
                    command.Parameters["startTime"].Value = aRoomAllocation.StartTime.TimeOfDay;

                    command.Parameters.Add("endTime", sqlDbType: SqlDbType.Time);
                    command.Parameters["endTime"].Value = aRoomAllocation.EndTime.TimeOfDay;

                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    return(reader.HasRows);
                }
        }
        public IHttpActionResult PutRoomAllocation(int id, RoomAllocation roomAllocation)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != roomAllocation.Id)
            {
                return BadRequest();
            }

           

            try
            {
                _RoomAllocationService.Update(roomAllocation);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoomAllocationExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 public bool TimeRangeCheck(RoomAllocation roomAllocation)
 {
     if (roomAllocation.FromTime > roomAllocation.ToTime)
     {
         return(false);
     }
     return(true);
 }
Example #12
0
 public ActionResult Allocate(RoomAllocation aRoomAllocation)
 {
     ViewBag.response    = aClassroomManager.Allocate(aRoomAllocation);
     ViewBag.Departments = aDepartmentManager.GetAllDepartments();
     ViewBag.Days        = aDayManager.GetAllDays();
     ViewBag.Rooms       = aRoomManager.GetAllRooms();
     return(View());
 }
        public ActionResult DeleteConfirmed(int id)
        {
            RoomAllocation roomallocation = db.RoomAllocations.Find(id);

            db.RoomAllocations.Remove(roomallocation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #14
0
 public void FillRoomAllocation(int numRooms)
 {
     for (int room = 0; room < numRooms; room++)
     {
         var groups    = RoomGroupsAllocated.Where(r => r.Item1 == room).Select(r => r.Item2).ToList();
         var groupsStr = groups.Count > 0 ? string.Join("; ", groups) : "";
         RoomAllocation.Add(room, groupsStr);
     }
 }
Example #15
0
        /// <summary>
        /// Fill Links object for Room Allocation
        /// </summary>
        /// <param name="roomAllocation">RoomAllocation object</param>
        public void FillRoomAllocationLinks(RoomAllocation roomAllocation)
        {
            var idObject = new { id = roomAllocation.Sno };

            roomAllocation.Links = new LinkHelper()
                                   .SetOptions(User, typeof(RoomAllocationsController), Url)
                                   .AddLink(nameof(RoomAllocationsController.PutRoomAllocation), idObject)
                                   .AddLink(nameof(RoomAllocationsController.DeleteRoomAllocation), idObject)
                                   .GetLinks();
        }
        public ActionResult RoomAllocation(RoomAllocation roomAllocation)
        {
            ViewBag.Message = roomAllocationSaveManager.SaveRoomAllocation(roomAllocation);
            List <Department> departmentsList = departmentManager.GetDepartmentsList();
            List <Room>       roomList        = roomManager.GetRoomList();

            ViewBag.departmentsList = departmentsList;
            ViewBag.roomList        = roomList;
            return(View());
        }
        //
        // GET: /RoomAllocation/Delete/5

        public ActionResult Delete(int id = 0)
        {
            RoomAllocation roomallocation = db.RoomAllocations.Find(id);

            if (roomallocation == null)
            {
                return(HttpNotFound());
            }
            return(View(roomallocation));
        }
Example #18
0
        public string AllocateRoom(RoomAllocation anAllocation)
        {
            RoomAllocationGateway RoomAllocGate = new RoomAllocationGateway();

            if (RoomAllocGate.AllocateRoom(anAllocation))
            {
                return("Saved Succesfully");
            }
            return("Save Failed");
        }
Example #19
0
 public string SaveRoomAllocation(RoomAllocation roomAllocation)
 {
     if (roomAllocationSaveGatway.SaveRoomAllocte(roomAllocation) > 0)
     {
         return("Allocation Successfull .");
     }
     else
     {
         return("Allocation Failed");
     }
 }
Example #20
0
        public int SaveRoomAllocte(RoomAllocation roomAllocation)
        {
            connection.ConnectionString = connectionString;
            string     sqlQuery = "INSERT INTO roomAllocation_tbl VALUES('" + roomAllocation.DepartmentId + "','" + roomAllocation.CourseId + "','" + roomAllocation.RoomNo + "','" + roomAllocation.DayList + "','" + roomAllocation.FromTime + " " + roomAllocation.FromExtension + "','" + roomAllocation.ToTime + " " + roomAllocation.ToExtension + "',1)";
            SqlCommand command  = new SqlCommand(sqlQuery, connection);

            connection.Open();
            int isInserted = command.ExecuteNonQuery();

            connection.Close();
            return(isInserted);
        }
Example #21
0
        public ActionResult Allocate(RoomAllocation aRoomAllocation)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            ViewBag.response    = aClassroomManager.Allocate(aRoomAllocation);
            ViewBag.Departments = aDepartmentManager.GetAllDepartments();
            ViewBag.Days        = aDayManager.GetAllDays();
            ViewBag.Rooms       = aRoomManager.GetAllRooms();
            return(View());
        }
 public ActionResult Edit(RoomAllocation roomallocation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(roomallocation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", roomallocation.DepartmentId);
     ViewBag.CourseId     = new SelectList(db.Courses, "CourseId", "Code", roomallocation.CourseId);
     ViewBag.RoomId       = new SelectList(db.Rooms, "RoomId", "Name", roomallocation.RoomId);
     ViewBag.DayId        = new SelectList(db.Days, "DayId", "Name", roomallocation.DayId);
     return(View(roomallocation));
 }
        //
        // GET: /RoomAllocation/Edit/5

        public ActionResult Edit(int id = 0)
        {
            RoomAllocation roomallocation = db.RoomAllocations.Find(id);

            if (roomallocation == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", roomallocation.DepartmentId);
            ViewBag.CourseId     = new SelectList(db.Courses, "CourseId", "Code", roomallocation.CourseId);
            ViewBag.RoomId       = new SelectList(db.Rooms, "RoomId", "Name", roomallocation.RoomId);
            ViewBag.DayId        = new SelectList(db.Days, "DayId", "Name", roomallocation.DayId);
            return(View(roomallocation));
        }
Example #24
0
        public async Task <IActionResult> PostRoomAllocation([FromBody] RoomAllocation roomAllocation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.RoomAllocation.Add(roomAllocation);
            Utilities.Log(_context, HttpContext, $"Create room allocation for room id {roomAllocation.RoomId}", 2, true);

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRoomAllocation", new { id = roomAllocation.Sno }, roomAllocation));
        }
        // GET: /Roomallocation/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RoomAllocation roomallocation = db.RoomAllocations.Find(id);

            if (roomallocation == null)
            {
                return(HttpNotFound());
            }
            return(View(roomallocation));
        }
        public bool AllocateRoom(RoomAllocation anAllocation)
        {
            string        connection = WebConfigurationManager.ConnectionStrings["UMS"].ConnectionString;
            SqlConnection con        = new SqlConnection(connection);

            con.Open();
            string     query = "INSERT INTO RoomAllocations VALUES(" + anAllocation.RoomId + "," + anAllocation.CourseId + " ," + anAllocation.DayNo + " , " + anAllocation.FromTime + ", " + anAllocation.ToTime + ", " + anAllocation.Status + ");";
            SqlCommand com   = new SqlCommand(query, con);
            int        flag  = com.ExecuteNonQuery();

            con.Close();
            if (flag > 0)
            {
                return(true);
            }
            return(false);
        }
Example #27
0
        public int InsertRoomAllocation(RoomAllocation roomAllocation)
        {
            SqlConnection connection = new SqlConnection(connectionString);


            //string query = "INSERT INTO RoomAllocation VALUES('" + roomAllocation.RoomId + "','" + roomAllocation.DayId + "','" + roomAllocation.CourseId + "','" + roomAllocation.FromTime.ToString("hh:mm") + "','" + roomAllocation.FromTimeSelected + "','" + roomAllocation.ToTime.ToString("hh:mm") + "','" + roomAllocation.ToTimeSelected + "','" + roomAllocation.DepartmentId + "')";
            //string status = "Located";
            string     query   = "INSERT INTO RoomAllocation(RoomId,DayId,CourseId,FromTime,ToTime,DeptId,RoomAllocationStatus) VALUES('" + roomAllocation.RoomId + "','" + roomAllocation.DayId + "','" + roomAllocation.CourseId + "','" + roomAllocation.FromTime.ToString("hh:mm tt") + "','" + roomAllocation.ToTime.ToString("hh:mm tt") + "','" + roomAllocation.DepartmentId + "'," + 1 + ")";
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            int rowAffected = command.ExecuteNonQuery();

            connection.Close();

            return(rowAffected);
        }
        // GET: /Roomallocation/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RoomAllocation roomallocation = db.RoomAllocations.Find(id);

            if (roomallocation == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CourseId     = new SelectList(db.Courses, "Id", "CourseCode", roomallocation.CourseId);
            ViewBag.DayId        = new SelectList(db.Days, "Id", "Name", roomallocation.DayId);
            ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DeptCode", roomallocation.DepartmentId);
            ViewBag.RoomId       = new SelectList(db.Rooms, "Id", "RoomNo", roomallocation.RoomId);
            return(View(roomallocation));
        }
Example #29
0
        public ActionResult Allocate([Bind(Include = "CourseId,DeptId,CourseId,RoomId,DayNo,FromTime,ToTime,Status")] RoomAllocation aRoomAllocation)
        {
            RoomAllocationManager RoomAllocMan = new RoomAllocationManager();

            ViewBag.msg     = RoomAllocMan.AllocateRoom(aRoomAllocation);
            ViewBag.deps    = DeptMan.GetAllDepartments();
            ViewBag.days    = DayMan.GetAllDays();
            ViewBag.rooms   = RoomMan.GetAllRooms();
            ViewBag.courses = new List <Course>
            {
                new Course()
                {
                    CourseId = -1, CourseName = "Select a Course"
                }
            };

            return(View());
        }
        public RoomAllocation GetAllocationInfo(string CourseCode)
        {
            RoomAllocation prevAllocation = new RoomAllocation();

            newDatabaseGateway.Command.CommandText = "SELECT * FROM ROOM_SCHEDULE WHERE CourseCode = '" + CourseCode + "' AND Valid = 'True';";
            newDatabaseGateway.Connection.Open();
            SqlDataReader reader = newDatabaseGateway.Command.ExecuteReader();

            while (reader.Read())
            {
                prevAllocation.Day      = reader["Day"].ToString();
                prevAllocation.RoomNo   = reader["RoomNo"].ToString();
                prevAllocation.FromTime = reader["FromTime"].ToString();
                prevAllocation.ToTime   = reader["ToTime"].ToString();
            }
            newDatabaseGateway.Connection.Close();
            return(prevAllocation);
        }
 public bool NoTimeOverlap(string FromTime, string ToTime, RoomAllocation prevAllocation)
 {
     if (LessThan(prevAllocation.FromTime, FromTime))
     {
         if (LessThan(FromTime, prevAllocation.ToTime))
         {
             return(true);
         }
     }
     else
     {
         if (LessThan(prevAllocation.FromTime, ToTime))
         {
             return(true);
         }
     }
     return(false);
 }
        public async Task<ActionResult> Index(int? Id, string sortOrder, string currentFilter, int? page, string error)
        {
            RoomAllocation roomAllocation = new RoomAllocation();
            SearchRoomAllocation searchroomAllocation = new SearchRoomAllocation();
            ViewBag.Error = error;
            if (Id != null)
            {
                roomAllocation =await _RoomAllocationRepository.GetById(Id.Value.ToString ());
                await GetTypes(roomAllocation.RoomTypeId, roomAllocation.WingId, roomAllocation.RoomStatusTypeId);
            }
            else
            { await GetTypes(1, 1, 1); }

            await GetSearchTypes(1, 1, 1);

            var roomallocations = getList(sortOrder, currentFilter, page, await _RoomAllocationRepository.GetAll());

            RoomAllocationViewModel model = new RoomAllocationViewModel { List = roomallocations, RoomAllocation = roomAllocation, SearchRoomAllocation = searchroomAllocation };
            return View(model);
        }
        public IHttpActionResult PostRoomAllocation(RoomAllocation roomAllocation)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _RoomAllocationService.Create(roomAllocation);

            return CreatedAtRoute("DefaultApi", new { id = roomAllocation.Id }, roomAllocation);
        }
        public async Task<ActionResult> Search(SearchRoomAllocation searchroomAllocation)
        {
            RoomAllocation roomAllocation = new RoomAllocation();
            await GetTypes(1,1,1);
           var roomallocations=await _RoomAllocationRepository.GetAll();
          roomallocations= roomallocations.Where(r => ((!string.IsNullOrEmpty(searchroomAllocation.SearchRoomNumber)) && r.RoomNumber.ToString() == searchroomAllocation.SearchRoomNumber)
                                        || ((searchroomAllocation.SearchRoomStatusTypeId != 0) && searchroomAllocation.SearchRoomStatusTypeId == r.RoomStatusTypeId)

                                        || ((searchroomAllocation.SearchWingId != 0) && searchroomAllocation.SearchWingId == r.WingId)
                                        || ((searchroomAllocation.SearchRoomTypeId != 0) && searchroomAllocation.SearchRoomTypeId == r.RoomTypeId)
                                    );

           var roomallocationslist = getList("", "", 1, roomallocations);

           await GetSearchTypes(searchroomAllocation.SearchRoomTypeId, searchroomAllocation.SearchWingId, searchroomAllocation.SearchRoomStatusTypeId);
           RoomAllocationViewModel model = new RoomAllocationViewModel { List = roomallocationslist, RoomAllocation = roomAllocation, SearchRoomAllocation = searchroomAllocation };
            return View("Index", model);

        }
        public async Task<ActionResult>  Save(RoomAllocation roomAllocation, RoomStatus_detailViewModel m )
        {
            if (await _RoomAllocationRepository.GetRoomNumberExists(roomAllocation.RoomNumber, roomAllocation.Id))
                            ModelState.AddModelError("RoomNumber", "Please enter unique room number");

            if (ModelState.IsValid)
            {
                if (roomAllocation.Id == 0)
                {
                     roomAllocation.RoomStatusTypeId = 1;
                   await _RoomAllocationRepository.Create(roomAllocation);
                }
                else
                {
                    if (roomAllocation.RoomStatusTypeId != 1)
                    {
                        m.RoomStatus_Detail.RoomAllocationId = roomAllocation.Id;
                        m.RoomStatus_Detail.RoomStatusTypeId = roomAllocation.RoomStatusTypeId;
                        if (m.newrec)

                          await  _RoomStatus_DetailRepository.Create(m.RoomStatus_Detail);

                        else
                            _RoomStatus_DetailRepository.Update(m.RoomStatus_Detail, m.RoomStatus_Detail.Id.ToString ());
                    }

                    _RoomAllocationRepository.Update(roomAllocation, roomAllocation.Id.ToString ());
                }

            }
            else
            {
                SearchRoomAllocation searchroomAllocation = new SearchRoomAllocation();

                await GetTypes(roomAllocation.RoomTypeId, roomAllocation.WingId, roomAllocation.RoomStatusTypeId  );
                await GetSearchTypes(1, 1, 1);
                var roomallocations = getList("", "", 1, await _RoomAllocationRepository.GetAll());
                RoomAllocationViewModel model = new RoomAllocationViewModel { List = roomallocations, RoomAllocation = roomAllocation, SearchRoomAllocation = searchroomAllocation };
                 return View("Index", model);
            }
            return RedirectToAction("Index");
        }