public JsonResult DeleteFile(string id) { if (String.IsNullOrEmpty(id)) { return(Json(new { Result = "Error" })); } try { Guid guid = new Guid(id); RoomPictureMapping fileDetail = dc.RoomPictureMappings.Find(guid); if (fileDetail == null) { return(Json(new { Result = "Error" })); } //Remove from database dc.RoomPictureMappings.Remove(fileDetail); dc.SaveChanges(); //Delete file from the file system var path = Path.Combine(Server.MapPath("~/Rotativa/RoomImage/"), fileDetail.RoomPictureMappingId + fileDetail.Extension); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } return(Json(new { Result = "OK" })); } catch (Exception ex) { return(Json(new { Result = "Error" })); } }
public ActionResult Edit(ViewModelRoom Model) { try { if (Model.MinCapacity > Model.MaxCapacity) { ViewBag.RoomtypeListVB = dc.RoomTypes.Where(x => x.IsActive == true && x.Status == 1).ToList(); ViewBag.FloorListVB = dc.Floors.Where(x => x.IsActive == true && x.Status == 1).ToList(); ViewBag.MinMax = "MinMax"; return(View("RoomForm", Model)); } var userDetail = SessionHelper.GetUserDetailFromSession(); if (userDetail == null) { return(RedirectToAction("Index", "Login", new { ReturnUrl = "/Rooms" })); } var UserId = Convert.ToInt32(userDetail.user.id); if (ModelState.IsValid) { //New Files for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0) { RoomPictureMapping rpc = new RoomPictureMapping(); var ActualfileName = Path.GetFileName(file.FileName); var FileTime = DateTime.Now.ToFileTime(); string fileName = Path.GetFileNameWithoutExtension(file.FileName) + "_" + FileTime + Path.GetExtension(file.FileName); rpc.FileName = fileName; rpc.ActualFileName = ActualfileName; rpc.Extension = Path.GetExtension(fileName); rpc.RoomPictureMappingId = Guid.NewGuid(); rpc.RoomId = Model.RoomId; rpc.CreatedDate = DateTime.Now; rpc.UpdatedDate = DateTime.Now; rpc.CreatedBy = UserId; rpc.UpdatedBy = UserId; dc.RoomPictureMappings.Add(rpc); dc.SaveChanges(); var path = Path.Combine(Server.MapPath("~/Rotativa/RoomImage/"), Path.GetFileNameWithoutExtension(file.FileName) + "_" + FileTime + Path.GetExtension(file.FileName)); file.SaveAs(path); } } var data = dc.Rooms.Where(x => x.RoomId == Model.RoomId).FirstOrDefault(); if (data != null) { data.FloorId = Model.FloorId; data.RoomTypeId = Model.RoomTypeId; data.RoomName = Model.RoomName; data.RoomNumber = (int)Model.RoomNumber; data.Description = Model.Description; data.Capacity = Model.Capacity; data.MinCapacity = Model.MinCapacity; data.MaxCapacity = Model.MaxCapacity; data.UpdatedBy = UserId; data.UpdatedDate = DateTime.Now; Model.Status = 1; Model.IsActive = true; TempData["update"] = "doneupdate"; dc.SaveChanges(); MRMLog _MRMLog = new MRMLog(); _MRMLog.UserId = Convert.ToInt32(UserId); _MRMLog.Action = "Update"; _MRMLog.Module = "Room Update Operation"; _MRMLog.Description = userDetail.user.first_name + "_" + userDetail.user.last_name + " has Updated Room having id= " + Model.RoomId; _MRMLog.CreatedBy = Convert.ToInt32(UserId); _MRMLog.CraetedDate = DateTime.Now; dc.MRMLogs.Add(_MRMLog); dc.SaveChanges(); } return(RedirectToAction("Index", "Rooms")); } return(View("Roomform", Model)); } catch (Exception ex) { string filePath = Server.MapPath("~/Rotativa/Bug/Error.txt"); using (StreamWriter writer = new StreamWriter(filePath, true)) { writer.WriteLine("-----------------------------------------------------------------------------"); writer.WriteLine("Date : " + DateTime.Now.ToString()); writer.WriteLine(); while (ex != null) { writer.WriteLine(ex.GetType().FullName); writer.WriteLine("Message : " + ex.Message); writer.WriteLine("StackTrace : " + ex.StackTrace); writer.WriteLine("InnerException : " + ex.InnerException); ex = ex.InnerException; } } return(RedirectToAction("Index", "Login", new { ReturnUrl = "/Rooms" })); }; }
public ActionResult CreateRoom(ViewModelRoom Model) { try { if (Model.MinCapacity > Model.MaxCapacity) { ViewBag.RoomtypeListVB = dc.RoomTypes.Where(x => x.IsActive == true && x.Status == 1).ToList(); ViewBag.FloorListVB = dc.Floors.Where(x => x.IsActive == true && x.Status == 1).ToList(); ViewBag.MinMax = "MinMax"; return(View("Create", Model)); } var userDetail = SessionHelper.GetUserDetailFromSession(); if (userDetail == null) { return(RedirectToAction("Index", "Login", new { ReturnUrl = "/Rooms" })); } ObjectParameter returnId = new ObjectParameter("Exists", typeof(int)); var exist = dc.IsExistRooms(Model.RoomName, Model.RoomNumber, returnId).ToList(); int Roomexist = Convert.ToInt32(returnId.Value); if (Roomexist == 0) { var UserId = Convert.ToInt32(userDetail.user.id); Guid g = Guid.NewGuid(); if (ModelState.IsValid) { List <ViewModelRoomPictureMapping> fileDetails = new List <ViewModelRoomPictureMapping>(); for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0) { RoomPictureMapping rpc = new RoomPictureMapping(); var ActualfileName = Path.GetFileName(file.FileName); var FileTime = DateTime.Now.ToFileTime(); string fileName = Path.GetFileNameWithoutExtension(file.FileName) + "_" + FileTime + Path.GetExtension(file.FileName); rpc.FileName = fileName; rpc.ActualFileName = ActualfileName; rpc.Extension = Path.GetExtension(fileName); rpc.RoomPictureMappingId = Guid.NewGuid(); rpc.RoomId = g; rpc.CreatedDate = DateTime.Now; rpc.UpdatedDate = DateTime.Now; rpc.CreatedBy = UserId; rpc.UpdatedBy = UserId; dc.RoomPictureMappings.Add(rpc); dc.SaveChanges(); var path = Path.Combine(Server.MapPath("~/Rotativa/RoomImage/"), Path.GetFileNameWithoutExtension(file.FileName) + "_" + FileTime + Path.GetExtension(file.FileName)); file.SaveAs(path); } } Room rm = new Room(); rm.RoomId = g; rm.IsActive = true; rm.Status = 1; rm.CreatedDate = DateTime.Now; rm.UpdatedDate = DateTime.Now; rm.FloorId = Model.FloorId; rm.RoomTypeId = Model.RoomTypeId; rm.Capacity = Model.Capacity; rm.MinCapacity = Model.MinCapacity; rm.MaxCapacity = Model.MaxCapacity; rm.RoomNumber = Model.RoomNumber; rm.RoomName = Model.RoomName; rm.Description = Model.Description; rm.CreatedBy = UserId; rm.UpdatedBy = UserId; dc.Rooms.Add(rm); dc.SaveChanges(); MRMLog _MRMLog = new MRMLog(); _MRMLog.UserId = Convert.ToInt32(UserId); _MRMLog.Action = "Create"; _MRMLog.Module = "Room Create Operation"; _MRMLog.Description = userDetail.user.first_name + "_" + userDetail.user.last_name + " has Create Room having id= " + g; _MRMLog.CreatedBy = Convert.ToInt32(UserId); _MRMLog.CraetedDate = DateTime.Now; dc.MRMLogs.Add(_MRMLog); dc.SaveChanges(); TempData["create"] = "donecrate"; return(RedirectToAction("Index", "Rooms")); } return(View("Create", Model)); } else { ViewBag.RoomtypeListVB = dc.RoomTypes.Where(x => x.IsActive == true && x.Status == 1).ToList(); ViewBag.FloorListVB = dc.Floors.Where(x => x.IsActive == true && x.Status == 1).ToList(); Model.IsExist = true; ViewBag.IsExistRoom = 1; return(View("Create", Model)); } } catch (Exception ex) { return(RedirectToAction("Index", "Login", new { ReturnUrl = "/Rooms" })); } }