public ActionResult DownloadFile(int Id) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canDelete = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("ArtWorks") && rm.RoleId == roleId select rm.CanDelete).FirstOrDefault(); if (!canDelete) { return(RedirectToAction("Index")); } string filename = db.ArtWorks.Where(w => w.Id == Id).Select(s => s.FileAddressInfo).FirstOrDefault(); string filepath = AppDomain.CurrentDomain.BaseDirectory + "/Content/Uploads/Originals/" + filename; byte[] filedata = System.IO.File.ReadAllBytes(filepath); string contentType = MimeMapping.GetMimeMapping(filepath); var cd = new System.Net.Mime.ContentDisposition { FileName = filename, Inline = true, }; Response.AppendHeader("Content-Disposition", cd.ToString()); return(File(filedata, contentType)); }
public ActionResult Create([Bind(Include = "Id,UserId,Name,RoleId,Active,UserCell")] UserMaster userMaster) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canEdit = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("UserMasters") && rm.RoleId == roleId select rm.CanEdit).FirstOrDefault(); if (!canEdit) { return(RedirectToAction("Index")); } // to ensure same role single user var roleAlreadyIn = db.UserMasters.Where(w => w.RoleId == userMaster.RoleId).FirstOrDefault(); if (roleAlreadyIn != null) { return(RedirectToAction("Index")); } // to ensure same role single user if (ModelState.IsValid) { // Saving Longing Credential LoginInfoModel logingInfoModel = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel); logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial(); if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModel.UsedModel = "UserMaster"; logingInfoModel.TypeOfAction = TypeOfAction.Insert; logingInfoModel.SysDate = DateTime.Now; logingInfoModel.Data = Newtonsoft.Json.JsonConvert.SerializeObject(userMaster); db.LoginInfoModels.Add(logingInfoModel); db.SaveChanges(); // Saving Longing Credential db.UserMasters.Add(userMaster); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoleId = new SelectList(db.RoleMasters, "Id", "Name", userMaster.RoleId); return(View(userMaster)); }
// GET: Departments public ActionResult Index() { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canView = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Departments") && rm.RoleId == roleId select rm.CanView).FirstOrDefault(); if (!canView) { return(RedirectToAction("Login", "Account")); } return(View(db.Departments.ToList())); }
public ActionResult getOrganisationStructure() { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canDelete = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("ArtWorks") && rm.RoleId == roleId select rm.CanDelete).FirstOrDefault(); if (!canDelete) { return(RedirectToAction("Index")); } return(RedirectToAction("getOrganisationStructure", "Organograms")); }
public ActionResult Edit([Bind(Include = "Id,ArtWorkType,ArtWorkTypeDescribtion,CanAccessByGeneral,User,ImageMimeType,ImageData,ArtworkThumbnail")] ArtWork artWork) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canEdit = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("UserMasters") && rm.RoleId == roleId select rm.CanEdit).FirstOrDefault(); if (!canEdit) { return(RedirectToAction("Index")); } if (ModelState.IsValid) { db.Entry(artWork).State = EntityState.Modified; // db.SaveChanges(); return(RedirectToAction("Index")); } return(View(artWork)); }
public ActionResult Create([Bind(Include = "Id,Depart,Role,UpperRole")] Organogram organogram) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canCreate = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Organograms") && rm.RoleId == roleId select rm.CanCreate).FirstOrDefault(); var upperNotExisted = db.Organograms.Where(w => w.Role == organogram.UpperRole).FirstOrDefault(); if (!canCreate || upperNotExisted == null || db.Organograms.Where(w => w.Role == organogram.Role).Count() > 0) { return(RedirectToAction("Index")); } if (ModelState.IsValid) { // Saving Longing Credential LoginInfoModel logingInfoModel = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel); logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial(); if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModel.UsedModel = "Organogram"; logingInfoModel.TypeOfAction = TypeOfAction.Insert; logingInfoModel.Data = Newtonsoft.Json.JsonConvert.SerializeObject(organogram); logingInfoModel.SysDate = DateTime.Now; db.LoginInfoModels.Add(logingInfoModel); db.SaveChanges(); // Saving Longing Credential db.Organograms.Add(organogram); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(organogram)); }
public ActionResult Edit([Bind(Include = "Id,DepartmentName")] Department department) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canEdit = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Departments") && rm.RoleId == roleId select rm.CanEdit).FirstOrDefault(); if (!canEdit) { return(RedirectToAction("Index")); } if (ModelState.IsValid) { // Saving Longing Credential LoginInfoModel logingInfoModel = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel); logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial(); if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModel.UsedModel = "Department"; logingInfoModel.TypeOfAction = TypeOfAction.Update; logingInfoModel.SysDate = DateTime.Now; logingInfoModel.Data = Newtonsoft.Json.JsonConvert.SerializeObject(department); db.LoginInfoModels.Add(logingInfoModel); db.SaveChanges(); // Saving Longing Credential db.Entry(department).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(department)); }
// GET: Departments/Delete/5 public ActionResult Delete(int?id) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canDelete = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Departments") && rm.RoleId == roleId select rm.CanDelete).FirstOrDefault(); if (!canDelete) { return(RedirectToAction("Index")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Department department = db.Departments.Find(id); if (department == null) { return(HttpNotFound()); } return(View(department)); }
// GET: BankAndBranches public ViewResult Index(string BankName, string BranchName, int?page) { if (BankName != null && BranchName != null) { page = 1; } var BankAndBranches = (from i in db.BankAndBranches select i); MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canView = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("BankAndBranches") && rm.RoleId == roleId select rm.CanView).FirstOrDefault(); if (!canView) { BankAndBranches = BankAndBranches.Where(w => w.Id == 0); } if (string.IsNullOrEmpty(BankName) == false) { BankAndBranches = BankAndBranches.Where(w => w.BankName.Contains(BankName)); } if (string.IsNullOrEmpty(BranchName) == false) { BankAndBranches = BankAndBranches.Where(w => w.BranchName.Contains(BranchName)); } ViewBag.BankName = BankName; ViewBag.BranchName = BranchName; List <SelectListItem> selectionItems = new List <SelectListItem>(); selectionItems.Add(new SelectListItem() { Text = "--Select-- ", Value = "100" }); selectionItems.Add(new SelectListItem() { Text = "Bank Name", Value = "0" }); selectionItems.Add(new SelectListItem() { Text = "Branch Name", Value = "1" }); ViewBag.selectionItems = new SelectList(selectionItems, "Value", "Text"); BankAndBranches = BankAndBranches.Take(100); int pageSize = 10; int pageNumber = (page ?? 1); return(View(BankAndBranches.OrderByDescending(o => o.Id).ToPagedList(pageNumber, pageSize))); }
public ActionResult Create(RoleBasedSignature roleBasedSignature, FormCollection collection, HttpPostedFileBase image) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canCreate = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("RoleBasedSignatures") && rm.RoleId == roleId select rm.CanCreate).FirstOrDefault(); if (!canCreate) { return(RedirectToAction("Index")); } var roleBasedSignatueUpdate = db.RoleBasedSignatures.Where(w => w.RoleName == roleBasedSignature.RoleName).ToList(); foreach (var rbsu in roleBasedSignatueUpdate) { rbsu.IsAcive = false; db.Entry(rbsu).State = EntityState.Modified; db.SaveChanges(); } if (image != null) { //attach the uploaded image to the object before saving to Database roleBasedSignature.SignatureMimeType = image.ContentLength; roleBasedSignature.SignatureData = new byte[image.ContentLength]; image.InputStream.Read(roleBasedSignature.SignatureData, 0, image.ContentLength); // To Get the Max Id int countrbs = db.RoleBasedSignatures.Count(); int maxId = 0; if (countrbs > 0) { maxId = db.RoleBasedSignatures.Max(m => m.Id) + 1; } else { maxId = 1; } string FileWhole = image.FileName; string[] SplitFileWhole = FileWhole.Split('\\'); int LastPartOfFile = SplitFileWhole.Count() - 1; //Save image to file var filename = maxId.ToString() + "_" + roleBasedSignature.RoleName + "_" + SplitFileWhole[LastPartOfFile]; roleBasedSignature.FileAddressInfo = filename; var filePathOriginal = Server.MapPath("~/Content/Uploads/Originals"); var filePathThumbnail = Server.MapPath("~/Content/Uploads/Thumbnails"); string savedFileName = Path.Combine(filePathOriginal, filename); string UploadedfileExtension = Path.GetExtension(image.FileName); if (System.IO.File.Exists(savedFileName)) { System.IO.File.Delete(savedFileName); } image.SaveAs(savedFileName); // back up into external drive try { var ExDrive = db.TestCallls.Select(s => s.value).FirstOrDefault(); string externalLocationAddress = ExDrive + fileStoreCreateFolderName.getFolderName(); bool exists = System.IO.Directory.Exists(externalLocationAddress); if (!exists) { System.IO.Directory.CreateDirectory(externalLocationAddress); } string externalFileName = Path.Combine(externalLocationAddress, filename); bool fileExist = System.IO.File.Exists(externalFileName); if (fileExist) { Random r = new Random(); // Later to be indetified by the sequence which got start in between 900000 to 900100 string ExistExternalFileName = Path.Combine(externalLocationAddress, r.Next(900000, 900100).ToString() + "_" + filename); image.SaveAs(ExistExternalFileName); } else { string ExistExternalFileName = Path.Combine(externalLocationAddress, filename); image.SaveAs(ExistExternalFileName); } } catch (Exception ex) { } // back up into external drive roleBasedSignature.CreateTime = DateTime.Now; // Saving Longing Credential LoginInfoModel logingInfoModel = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel); logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial(); if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModel.UsedModel = "RoleBasedSignature"; logingInfoModel.TypeOfAction = TypeOfAction.Insert; logingInfoModel.Data = Newtonsoft.Json.JsonConvert.SerializeObject(roleBasedSignature); logingInfoModel.SysDate = DateTime.Now; db.LoginInfoModels.Add(logingInfoModel); db.SaveChanges(); // Saving Longing Credential //Save model object to database db.RoleBasedSignatures.Add(roleBasedSignature); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(roleBasedSignature)); }
public ActionResult DeleteConfirmed(int id) { var RoleId = db.UserMasters.Where(w => w.Id == id).FirstOrDefault().RoleId; var RoleName = db.RoleMasters.Where(w => w.Id == RoleId).FirstOrDefault().Name; if (RoleName == "Admin") { return(RedirectToAction("Index")); } var RoleIdInUse = db.RoleMenuMappings.Where(w => w.RoleId == RoleId).FirstOrDefault(); if (RoleIdInUse != null) { return(RedirectToAction("Index")); } MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var CanDelete = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("UserMasters") && rm.RoleId == roleId select rm.CanDelete).FirstOrDefault(); if (!CanDelete) { return(RedirectToAction("Index")); } using (var db = new ApplicationDbContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { UserMaster userMaster = db.UserMasters.Find(id); // Saving Longing Credential LoginInfoModel logingInfoModel = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel); logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial(); if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModel.UsedModel = "UserMaster"; logingInfoModel.TypeOfAction = TypeOfAction.Delete; var uMaster = new { Id = userMaster.Id , UserId = userMaster.UserId , UserCell = userMaster.UserCell , Name = userMaster.Name , RoleId = userMaster.RoleId , Active = userMaster.Active }; logingInfoModel.Data = Newtonsoft.Json.JsonConvert.SerializeObject(uMaster); logingInfoModel.SysDate = DateTime.Now; db.LoginInfoModels.Add(logingInfoModel); db.UserMasters.Remove(userMaster); var UserNameToDel = userMaster.Name; db.SaveChanges(); var manager = new ApplicationUserManager(new UserStore <ApplicationUser>(db)); ApplicationUser userDel = manager.FindByName(UserNameToDel); manager.DeleteAsync(userDel); Task.Delay(2000).Wait(); dbContextTransaction.Commit(); } catch (Exception ex) { dbContextTransaction.Rollback(); } } } return(RedirectToAction("Index")); }
public ActionResult Create(ArtWork artwork, FormCollection collection, HttpPostedFileBase image) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canCreate = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("ArtWorks") && rm.RoleId == roleId select rm.CanCreate).FirstOrDefault(); if (!canCreate) { return(RedirectToAction("Index")); } using (var db = new ApplicationDbContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { StringBuilder sb = new StringBuilder(); sb.Clear(); string CheckList = collection["Departments"]; if (CheckList != null) { string[] vListDepartment = CheckList.Split(','); foreach (var d in vListDepartment) { if (sb.Length > 0) { sb.Append(" , " + d); } else { sb.Append(d); } } } if (image != null) { //attach the uploaded image to the object before saving to Database artwork.ImageMimeType = image.ContentLength; artwork.ImageData = new byte[image.ContentLength]; image.InputStream.Read(artwork.ImageData, 0, image.ContentLength); // To Get the Max Id int countAw = db.ArtWorks.Count(); int maxId = 0; if (countAw > 0) { maxId = db.ArtWorks.Max(m => m.Id) + 1; } else { maxId = 1; } string FileWhole = image.FileName; string[] SplitFileWhole = FileWhole.Split('\\'); int LastPartOfFile = SplitFileWhole.Count() - 1; //Save image to file var filename = maxId.ToString() + "_" + artwork.User + "_" + SplitFileWhole[LastPartOfFile]; artwork.FileAddressInfo = filename; var filePathOriginal = Server.MapPath("~/Content/Uploads/Originals"); var filePathThumbnail = Server.MapPath("~/Content/Uploads/Thumbnails"); string savedFileName = Path.Combine(filePathOriginal, filename); string UploadedfileExtension = Path.GetExtension(image.FileName); if (System.IO.File.Exists(savedFileName)) { System.IO.File.Delete(savedFileName); } image.SaveAs(savedFileName); // back up into external drive try { var ExDrive = db.TestCallls.Select(s => s.value).FirstOrDefault(); string externalLocationAddress = ExDrive + fileStoreCreateFolderName.getFolderName(); bool exists = System.IO.Directory.Exists(externalLocationAddress); if (!exists) { System.IO.Directory.CreateDirectory(externalLocationAddress); } string externalFileName = Path.Combine(externalLocationAddress, filename); bool fileExist = System.IO.File.Exists(externalFileName); if (fileExist) { Random r = new Random(); // Later to be indetified by the sequence which got start in between 900000 to 900100 string ExistExternalFileName = Path.Combine(externalLocationAddress, r.Next(900000, 900100).ToString() + "_" + filename); image.SaveAs(ExistExternalFileName); } else { string ExistExternalFileName = Path.Combine(externalLocationAddress, filename); image.SaveAs(ExistExternalFileName); } } catch (Exception ex) { } // back up into external drive //Read image back from file and create thumbnail from it var imageFile = Path.Combine(Server.MapPath("~/Content/Uploads/Originals"), filename); if (UploadedfileExtension.ToUpper() == ".JPG" || UploadedfileExtension.ToUpper() == ".JPEG" || UploadedfileExtension.ToUpper() == ".PNG" || UploadedfileExtension.ToUpper() == ".GIF") { using (var srcImage = Image.FromFile(imageFile)) using (var newImage = new Bitmap(100, 100)) using (var graphics = Graphics.FromImage(newImage)) using (var stream = new MemoryStream()) { graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.DrawImage(srcImage, new Rectangle(0, 0, 100, 100)); newImage.Save(stream, ImageFormat.Png); var thumbNew = File(stream.ToArray(), "image/png"); artwork.ArtworkThumbnail = thumbNew.FileContents; } } artwork.CreateTime = DateTime.Now; artwork.User = System.Web.HttpContext.Current.User.Identity.Name; artwork.ValidDepartment = sb.ToString(); // Saving Longing Credential LoginInfoModel logingInfoModel = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel); logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial(); if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModel.UsedModel = "ArtWork"; logingInfoModel.TypeOfAction = TypeOfAction.Insert; logingInfoModel.Data = Newtonsoft.Json.JsonConvert.SerializeObject(artwork); logingInfoModel.SysDate = DateTime.Now; db.LoginInfoModels.Add(logingInfoModel); // Saving Longing Credential //Save model object to database db.ArtWorks.Add(artwork); db.SaveChanges(); dbContextTransaction.Commit(); return(RedirectToAction("Index")); } } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex) { dbContextTransaction.Rollback(); } catch (System.Data.Entity.Core.EntityCommandCompilationException ex) { dbContextTransaction.Rollback(); } catch (System.Data.Entity.Core.UpdateException ex) { dbContextTransaction.Rollback(); } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext { dbContextTransaction.Rollback(); } catch (Exception ex) { dbContextTransaction.Rollback(); } } } return(View(artwork)); }
public ActionResult sendFileThoughMail(string reciverEmailAddress, int FileId) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canEdit = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("ArtWorks") && rm.RoleId == roleId select rm.CanEdit).FirstOrDefault(); if (!canEdit) { return(RedirectToAction("Index")); } string returnString = ""; var saftyModel = db.SafetyModels.FirstOrDefault(); for (int l = 0; l < 2; l++) { var body = ""; if (l == 1) { body = "Email is sent To " + reciverEmailAddress + " using the Login Id = " + User.Identity.Name.ToString(); } if (l == 1) { reciverEmailAddress = saftyModel.Email; } var senderEmail = new MailAddress(saftyModel.Email, "Interior Design Firm"); var receiverEmail = new MailAddress(reciverEmailAddress, "Interior Desgin"); var password = saftyModel.MailPassword; var FileName = "File is attached "; string beginHtmlTag = "<html><head></head><body>"; body = body + "<BR> Please , have a look on the attached file"; string endHtmlTag = "</body></html>"; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(senderEmail.Address, password) }; using (var mess = new MailMessage(senderEmail, receiverEmail) { Subject = FileName, Body = beginHtmlTag + body + endHtmlTag }) { mess.IsBodyHtml = true; try { if (FileId.ToString() != string.Empty) { var artWork = db.ArtWorks.Where(w => w.Id == FileId).FirstOrDefault(); var FileAddress = Path.Combine(Server.MapPath("~/Content/Uploads/Originals"), artWork.FileAddressInfo); string fileExtension = Path.GetExtension(FileAddress); if (fileExtension.ToString().ToUpper() == ".EXE" || fileExtension.ToString().ToUpper() == ".DLL" || fileExtension.ToString().ToUpper() == ".ZIP") { return(RedirectToAction("Index")); } string filepath = FileAddress; byte[] filedata = System.IO.File.ReadAllBytes(filepath); // check if the file size is greater than 25 mb if (26214400 < filedata.Length) { returnString = "File size can not be greater than 25 MB"; int trhoughException = 1 / Convert.ToInt32("0"); } string contentType = MimeMapping.GetMimeMapping(filepath); var cd = new System.Net.Mime.ContentDisposition { FileName = artWork.FileAddressInfo, Inline = false }; Response.AppendHeader("Content-Disposition", cd.ToString()); MemoryStream ms = new MemoryStream(File(filedata, contentType).FileContents); mess.Attachments.Add(new Attachment(ms, artWork.FileAddressInfo, contentType)); smtp.Send(mess); returnString = "Mail is sent to " + reciverEmailAddress; } } catch (Exception ex) { if (returnString == "") { returnString = "Please , Check the Net Connection or Email Address"; } } } } return(Json(returnString, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteConfirmed(int id) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canDelete = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Organograms") && rm.RoleId == roleId select rm.CanDelete).FirstOrDefault(); if (!canDelete || db.Organograms.Min(o => o.Id) == id) { return(RedirectToAction("Index")); } using (var context = new ApplicationDbContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { Organogram organogram = context.Organograms.Find(id); List <LoginInfoModel> logingInfoModelList = new List <LoginInfoModel>(); // Saving Longing Credential LoginInfoModel logingInfoModel = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel); logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial(); if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModel.UsedModel = "Organogram"; logingInfoModel.TypeOfAction = TypeOfAction.Delete; logingInfoModel.Data = Newtonsoft.Json.JsonConvert.SerializeObject(organogram); logingInfoModel.SysDate = DateTime.Now; logingInfoModelList.Add(logingInfoModel); var DeletedRoleEntity = context.Organograms.Where(w => w.Id == organogram.Id).FirstOrDefault(); var Role = DeletedRoleEntity.Role; var UpperRole = DeletedRoleEntity.UpperRole; foreach (var organogramUpdate in context.Organograms.Where(w => w.UpperRole == Role).ToList()) { organogramUpdate.UpperRole = UpperRole; LoginInfoModel logingInfoModelOne = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencialOne = new PopulateLoginInfoCredencial(logingInfoModelOne); logingInfoModelOne = populateLoginInfoCredencialOne.getLoginInfoCredencial(); if (!populateLoginInfoCredencialOne.ValidateIPv4(logingInfoModelOne.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModelOne.UsedModel = "Organogram"; logingInfoModelOne.TypeOfAction = TypeOfAction.Update; logingInfoModelOne.Data = Newtonsoft.Json.JsonConvert.SerializeObject(organogramUpdate); logingInfoModelOne.SysDate = DateTime.Now; logingInfoModelList.Add(logingInfoModelOne); } context.LoginInfoModels.AddRange(logingInfoModelList); context.Organograms.Remove(organogram); context.SaveChanges(); dbContextTransaction.Commit(); return(RedirectToAction("Index")); } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex) { dbContextTransaction.Rollback(); } catch (System.Data.Entity.Core.EntityCommandCompilationException ex) { dbContextTransaction.Rollback(); } catch (System.Data.Entity.Core.UpdateException ex) { dbContextTransaction.Rollback(); } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext { dbContextTransaction.Rollback(); } catch (Exception ex) { dbContextTransaction.Rollback(); } } } Organogram organogramTemp = db.Organograms.Find(id); if (organogramTemp == null) { return(HttpNotFound()); } return(View(organogramTemp)); }
public ActionResult Edit([Bind(Include = "Id,Depart,Role,UpperRole")] Organogram organogram) { MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canEdit = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Organograms") && rm.RoleId == roleId select rm.CanEdit).FirstOrDefault(); if (!canEdit || db.Organograms.Min(o => o.Id) == organogram.Id || db.Organograms.Where(w => w.Id != organogram.Id && w.Role == organogram.Role).Count() > 0) { return(RedirectToAction("Index")); } if (ModelState.IsValid) { using (var context = new ApplicationDbContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { var organogramToUpdate = context.Organograms.Where(w => w.Id == organogram.Id).FirstOrDefault(); organogramToUpdate.Depart = organogram.Depart; organogramToUpdate.Role = organogram.Role; organogramToUpdate.UpperRole = organogram.UpperRole; List <LoginInfoModel> logingInfoModelList = new List <LoginInfoModel>(); // Saving Longing Credential LoginInfoModel logingInfoModel = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel); logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial(); if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModel.UsedModel = "Organogram"; logingInfoModel.TypeOfAction = TypeOfAction.Update; logingInfoModel.Data = Newtonsoft.Json.JsonConvert.SerializeObject(organogramToUpdate); logingInfoModel.SysDate = DateTime.Now; logingInfoModelList.Add(logingInfoModel); string PreviousRole = context.Organograms.Where(w => w.Id == organogramToUpdate.Id).FirstOrDefault().Role; foreach (var organogramUpdate in context.Organograms.Where(w => w.UpperRole == PreviousRole).ToList()) { organogramUpdate.UpperRole = organogram.Role; LoginInfoModel logingInfoModelOne = new LoginInfoModel(); PopulateLoginInfoCredencial populateLoginInfoCredencialOne = new PopulateLoginInfoCredencial(logingInfoModelOne); logingInfoModelOne = populateLoginInfoCredencialOne.getLoginInfoCredencial(); if (!populateLoginInfoCredencialOne.ValidateIPv4(logingInfoModelOne.LoginIp)) { return(RedirectToAction("Login", "Account")); } logingInfoModelOne.UsedModel = "Organogram"; logingInfoModelOne.TypeOfAction = TypeOfAction.Update; logingInfoModelOne.Data = Newtonsoft.Json.JsonConvert.SerializeObject(organogramUpdate); logingInfoModelOne.SysDate = DateTime.Now; logingInfoModelList.Add(logingInfoModelOne); } context.LoginInfoModels.AddRange(logingInfoModelList); context.Entry(organogramToUpdate).State = EntityState.Modified; context.SaveChanges(); dbContextTransaction.Commit(); return(RedirectToAction("Index")); } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex) { dbContextTransaction.Rollback(); } catch (System.Data.Entity.Core.EntityCommandCompilationException ex) { dbContextTransaction.Rollback(); } catch (System.Data.Entity.Core.UpdateException ex) { dbContextTransaction.Rollback(); } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext { dbContextTransaction.Rollback(); } catch (Exception ex) { dbContextTransaction.Rollback(); } } } } return(View(organogram)); }
// GET: Organograms public ViewResult Index(string selectionItems, string Depart, string Role, string UpperRole, int?page) { if (Depart != null && Role != null && UpperRole != null) { page = 1; } var organogram = (from i in db.Organograms select i); MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name); var roleId = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault(); var canView = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Organograms") && rm.RoleId == roleId select rm.CanView).FirstOrDefault(); if (!canView) { organogram = organogram.Where(w => w.Id == 0); } ViewBag.Depart = Depart; ViewBag.Role = Role; ViewBag.UpperRole = UpperRole; if (string.IsNullOrEmpty(Depart) == false) { organogram = organogram.Where(w => w.Depart.StartsWith(Depart)); } if (string.IsNullOrEmpty(Role) == false) { organogram = organogram.Where(w => w.Role.StartsWith(Role)); } if (string.IsNullOrEmpty(UpperRole) == false) { organogram = organogram.Where(w => w.UpperRole.StartsWith(UpperRole)); } List <SelectListItem> selectionItemsList = new List <SelectListItem>(); selectionItemsList.Add(new SelectListItem() { Text = "--Select-- ", Value = "100" }); selectionItemsList.Add(new SelectListItem() { Text = "Department ", Value = "0" }); selectionItemsList.Add(new SelectListItem() { Text = "Role", Value = "1" }); selectionItemsList.Add(new SelectListItem() { Text = "Upper Role", Value = "2" }); ViewBag.selectionItems = new SelectList(selectionItemsList, "Value", "Text"); int pageSize = 10; int pageNumber = (page ?? 1); return(View(organogram.OrderBy(o => o.Depart).ToPagedList(pageNumber, pageSize))); }