public ActionResult EditAlbum(Gallery collection) { try { var httpPostedFile = HttpContext.Request.Files["UploadedImage"]; DSRCManagementSystemEntities1 db = new DSRCManagementSystemEntities1(); var value = db.Albums.Where(x => x.AlbumID == collection.AlbumID).Select(o => o).FirstOrDefault(); value.AlbumTitle = collection.AlbumTitle; value.AlbumDescription = collection.AlbumDescription; value.EventDate = collection.EventDate; string AlbumPath = ConfigurationManager.AppSettings["AlbumPath"].ToString() + collection.AlbumTitle; if (httpPostedFile != null) { var AlbumTitle = collection.AlbumTitle; var CoverPhotoName = Path.GetFileName(httpPostedFile.FileName); var FolderPath = Server.MapPath(AlbumPath); if (!Directory.Exists(FolderPath)) { Directory.CreateDirectory(FolderPath); } string FilePath = Server.MapPath(AlbumPath + "/" + CoverPhotoName); httpPostedFile.SaveAs(FilePath); value.AlbumCoverPhotoPath = ConfigurationManager.AppSettings["AlbumPath"].ToString() + AlbumTitle + "/" + CoverPhotoName; } db.SaveChanges(); if (collection.AlbumRole != null) { List <int?> objrole = new List <int?>(); string[] role = collection.AlbumRole.Split(','); for (int i = 0; i < role.Count(); i++) { objrole.Add(Convert.ToInt32(role[i])); } var deleterole = db.AlbumAccesses.Where(x => x.AlbumID == collection.AlbumID).Select(o => o).ToList(); foreach (var delrole in deleterole) { db.AlbumAccesses.DeleteObject(delrole); } db.SaveChanges(); for (int j = 0; j < objrole.Count(); j++) { DSRCManagementSystem.AlbumAccess objaccess = new DSRCManagementSystem.AlbumAccess(); objaccess.AlbumID = collection.AlbumID; objaccess.RoleID = objrole[j]; db.AddToAlbumAccesses(objaccess); db.SaveChanges(); } } else if (collection.AlbumUser != null) { List <int?> objuser = new List <int?>(); string[] user = collection.AlbumUser.Split(','); for (int i = 0; i < user.Count(); i++) { objuser.Add(Convert.ToInt32(user[i])); } var deleteuser = db.AlbumAccesses.Where(x => x.AlbumID == collection.AlbumID).Select(o => o).ToList(); foreach (var deluser in deleteuser) { db.AlbumAccesses.DeleteObject(deluser); } db.SaveChanges(); for (int j = 0; j < objuser.Count(); j++) { DSRCManagementSystem.AlbumAccess objaccess = new DSRCManagementSystem.AlbumAccess(); objaccess.AlbumID = collection.AlbumID; objaccess.UserId = objuser[j]; db.AddToAlbumAccesses(objaccess); db.SaveChanges(); } } else { var deleteuser = db.AlbumAccesses.Where(x => x.AlbumID == collection.AlbumID).Select(o => o).ToList(); foreach (var deluser in deleteuser) { db.AlbumAccesses.DeleteObject(deluser); } db.SaveChanges(); DSRCManagementSystem.AlbumAccess objaccess = new DSRCManagementSystem.AlbumAccess(); objaccess.AlbumID = collection.AlbumID; db.AddToAlbumAccesses(objaccess); db.SaveChanges(); } var deleteTag = db.TaggedAlbums.Where(x => x.AlbumId == collection.AlbumID).Select(o => o).ToList(); foreach (var deluser in deleteTag) { db.TaggedAlbums.DeleteObject(deluser); db.SaveChanges(); } string[] tagvalue = collection.TagUsers.Split(','); for (int i = 0; i < tagvalue.Count(); i++) { var objTagAlbum = db.TaggedAlbums.CreateObject(); objTagAlbum.AlbumId = collection.AlbumID; objTagAlbum.UserId = Convert.ToInt32(tagvalue[i]); db.TaggedAlbums.AddObject(objTagAlbum); db.SaveChanges(); } ViewBag.TagUsers = new MultiSelectList((from u in db.Users.Where(x => x.IsActive == true) select new { UserId = u.UserID, FullName = u.FirstName + " " + u.LastName, }).ToList(), "UserID", "FullName"); return(Json("success", JsonRequestBehavior.AllowGet)); } catch (Exception Ex) { string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); ExceptionHandlingController.ExceptionDetails(Ex, actionName, controllerName); return(Json("failed", JsonRequestBehavior.AllowGet)); } }
public ActionResult CreateAlbum(Gallery collection) { try { int sessionuserid = Convert.ToInt32(Session["UserID"]); var httpPostedFile = HttpContext.Request.Files["UploadedImage"] as HttpPostedFileBase; DSRCManagementSystemEntities1 objdb = new DSRCManagementSystemEntities1(); var obj = objdb.Albums.CreateObject(); var obj1 = objdb.DefaultAlbumUsers.CreateObject(); int AlbumID; string AlbumPath = ConfigurationManager.AppSettings["AlbumPath"].ToString() + collection.AlbumTitle; if (httpPostedFile != null) { var AlbumTitle = collection.AlbumTitle; var CoverPhotoName = Path.GetFileName(httpPostedFile.FileName); var FolderPath = Server.MapPath(AlbumPath); if (!Directory.Exists(FolderPath)) { Directory.CreateDirectory(FolderPath); } var filepath = Server.MapPath(AlbumPath + "/" + CoverPhotoName); Image image = Image.FromStream(httpPostedFile.InputStream, true, true); if (image.Width > 1024 || image.Height > 768) { int newwidthimg = 1024; float AspectRatio = (float)image.Size.Width / (float)image.Size.Height; int newHeight = 768; Image thumbNail = new Bitmap(newwidthimg, newHeight, image.PixelFormat); Graphics g = Graphics.FromImage(thumbNail); g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; Rectangle rect = new Rectangle(0, 0, newwidthimg, newHeight); g.DrawImage(image, rect); thumbNail.Save(Server.MapPath(AlbumPath + "/" + httpPostedFile.FileName + ".jpg"), ImageFormat.Jpeg); } else { image.Save(Server.MapPath(AlbumPath + "/" + httpPostedFile.FileName + ".jpg"), ImageFormat.Jpeg); } string CreatedBy = Convert.ToString(Session["FirstName"]) + " " + Convert.ToString(Session["LastName"]); DateTime CreatedOn = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE); obj.AlbumTitle = AlbumTitle; obj.AlbumDescription = collection.AlbumDescription; obj.AlbumCoverPhotoPath = ConfigurationManager.AppSettings["AlbumPath"].ToString() + AlbumTitle + "/" + CoverPhotoName + ".jpg"; obj.CreatedDate = CreatedOn; obj.CreatedBy = CreatedBy; obj.EventDate = collection.EventDate; obj.IsActive = true; objdb.Albums.AddObject(obj); objdb.SaveChanges(); AlbumID = (from p in objdb.Albums where p.AlbumTitle == collection.AlbumTitle && p.IsActive == true select p.AlbumID).SingleOrDefault(); obj1.AlbumID = AlbumID; obj1.UserID = Convert.ToInt32(Session["UserID"]); obj1.IsActive = true; objdb.DefaultAlbumUsers.AddObject(obj1); objdb.SaveChanges(); if (collection.TagUsers != null && collection.TagUsers != "") { string[] value = collection.TagUsers.Split(','); for (int i = 0; i < value.Count(); i++) { var objTagAlbum = objdb.TaggedAlbums.CreateObject(); objTagAlbum.AlbumId = AlbumID; objTagAlbum.UserId = Convert.ToInt32(value[i]); objdb.TaggedAlbums.AddObject(objTagAlbum); objdb.SaveChanges(); } } if (collection.AlbumRole != null) { List <int?> objrole = new List <int?>(); string[] role = collection.AlbumRole.Split(','); for (int i = 0; i < role.Count(); i++) { objrole.Add(Convert.ToInt32(role[i])); } for (int i = 0; i < objrole.Count(); i++) { DSRCManagementSystem.AlbumAccess objaccess = new DSRCManagementSystem.AlbumAccess(); objaccess.AlbumID = AlbumID; objaccess.RoleID = objrole[i]; objdb.AddToAlbumAccesses(objaccess); objdb.SaveChanges(); } } else if (collection.AlbumUser != null) { List <int?> objuser = new List <int?>(); string[] user = collection.AlbumUser.Split(','); for (int i = 0; i < user.Count(); i++) { objuser.Add(Convert.ToInt32(user[i])); } for (int i = 0; i < objuser.Count(); i++) { DSRCManagementSystem.AlbumAccess objaccess1 = new DSRCManagementSystem.AlbumAccess(); objaccess1.AlbumID = AlbumID; objaccess1.UserId = objuser[i]; objdb.AddToAlbumAccesses(objaccess1); objdb.SaveChanges(); } } else { DSRCManagementSystem.AlbumAccess objaccess2 = new DSRCManagementSystem.AlbumAccess(); objaccess2.AlbumID = AlbumID; objdb.AddToAlbumAccesses(objaccess2); objdb.SaveChanges(); } //var tagusers = (from u in objdb.Users.Where(x => x.IsActive == true && x.UserID != sessionuserid) // select new // { // UserId = u.UserID, // FullName = u.FirstName + " " + u.LastName, // }).ToList(); ViewBag.TagUsers = new MultiSelectList((from u in objdb.Users.Where(x => x.IsActive == true && x.UserID != sessionuserid) select new { UserId = u.UserID, FullName = u.FirstName + " " + u.LastName, }).ToList(), "UserId", "FullName"); } return(Json("success", JsonRequestBehavior.AllowGet)); } catch (Exception Ex) { string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); ExceptionHandlingController.ExceptionDetails(Ex, actionName, controllerName); return(Json("failed", JsonRequestBehavior.AllowGet)); } }