public ActionResult RemoveDocument(Guid Id, Guid OrganisationId) { Document document = db.Documents.Find(Id); if (null == document) { ControllerMessage.Error(this, "Document not found"); return(RedirectToAction("details", new { Id = OrganisationId })); } var uploadPath = Server.MapPath(SystemSettings.GetStringValue("DocumentPath")); var fileName = uploadPath + document.Name; var exist = System.IO.File.Exists(fileName); if (exist) { Organisation o = db.Organisations.Find(OrganisationId); if (null == o) { ControllerMessage.Error(this, "Invalid request"); return(RedirectToAction("index")); } System.IO.File.Delete(fileName); o.Documents.Remove(document); db.Documents.Remove(document); db.SaveChanges(); ControllerMessage.Success(this, "Document deleted!"); } return(RedirectToAction("details", new { id = OrganisationId })); }
public ActionResult Create(RoleViewModel ViewModel) { try { // TODO: Add insert logic here if (ModelState.IsValid) { var role = new IdentityRole(); role.Name = ViewModel.RoleForm.Name; roleManager.Create(role); ControllerMessage.Success(this, "Role: " + role.Name + " created!"); return(RedirectToAction("Index")); } ControllerMessage.Error(this, "Invalid submission!"); return(RedirectToAction("Index")); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); ControllerMessage.Error(this, SystemSettings.GetStringValue("SystemError")); return(RedirectToAction("Index")); } }
public ActionResult Edit(OrganisationViewModel ViewModel) { try { // TODO: Add update logic here var form = ViewModel.OrganisationForm; if (ModelState.IsValid) { Organisation o = db.Organisations.Find(form.Id); if (null == o) { ControllerMessage.Error(this, "Organisation not found!"); return(RedirectToAction("details", new { Id = form.Id })); } o.Name = form.Name; o.RCNumber = form.RCNumber; o.RegistrarId = form.RegistrarId; o.TIN = form.TIN; o.Website = form.Website; o.RegistrationYear = form.RegistrationYear; o.ModifiedBy = User.Identity.Name; o.ModifiedDate = DateTime.Now; db.SaveChanges(); ControllerMessage.Success(this, "Company details updated!"); return(RedirectToAction("details", new { Id = form.Id })); } ControllerMessage.Error(this, "Invalid form!"); return(RedirectToAction("details", new { Id = form.Id })); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); ControllerMessage.Error(this, "System error! Contact us if this is persistance"); return(RedirectToAction("Index")); } }
public ActionResult Status(MOrganisationViewModel ViewModel) { try { if (ModelState.IsValid) { var form = ViewModel.StatusForm; var organisation = db.Organisations.Find(form.Id); if (null == organisation) { ControllerMessage.Error(this, "Invalid organisation!"); return(RedirectToAction("index")); } if (organisation.OrganisationStatu.Id.Equals(form.Status)) { ControllerMessage.Error(this, "Select a different status"); return(RedirectToAction("details", new { id = form.Id })); } organisation.Status = form.Status; db.SaveChanges(); ControllerMessage.Success(this, "Company status: " + organisation.OrganisationStatu.Name); return(RedirectToAction("details", new { id = form.Id })); } ControllerMessage.Error(this, "Fill form correct"); return(RedirectToAction("details", new { id = ViewModel.StatusForm.Id })); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); ControllerMessage.Error(this, "System error! Contact us if this is persistance"); return(RedirectToAction("Index")); } }
public ActionResult Update(ProfileViewModel ViewModel) { try { if (ModelState.IsValid) { var form = ViewModel.ProfileForm; AspNetUser user = db.AspNetUsers.Where(x => x.UserName.Equals(User.Identity.Name)).FirstOrDefault(); if (null == user.UserProfile) { user.UserProfile = new UserProfile(); user.UserProfile.CreatedBy = User.Identity.Name; user.UserProfile.CreatedDate = DateTime.Now; } user.UserProfile.Firstname = form.Firstname; user.UserProfile.Surname = form.Surname; user.UserProfile.Profession = form.Profession; user.UserProfile.ModifiedBy = User.Identity.Name; user.UserProfile.ModifiedDate = DateTime.Now; db.SaveChanges(); ControllerMessage.Success(this, "Profile updated"); return(RedirectToAction("index")); } ControllerMessage.Error(this, "Please fill form correctly!"); return(RedirectToAction("index")); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); ControllerMessage.Error(this, "System Error"); return(RedirectToAction("index")); } }
public ActionResult AddDocument(OrganisationViewModel ViewModel) { try { if (ModelState.IsValid) { var form = ViewModel.OrganisationDocumentForm; Organisation o = db.Organisations.Find(form.OrganisationId); if (null == o) { ControllerMessage.Error(this, "Invalid form!"); return(RedirectToAction("index")); } DocumentType type = db.DocumentTypes.Find(form.DocumentType); if (null == type) { ControllerMessage.Error(this, "Invalid form!"); return(RedirectToAction("index")); } string fileExtension = Path.GetExtension(form.File.FileName); string fileName = Utility.GenerateRandomString(DateTime.Now.Ticks.ToString()) + fileExtension; // Check the extension to ensure compartibility if (!type.DocumentFormat.Name.Equals(fileExtension.ToLower())) { ControllerMessage.Error(this, "Invalid file type! Please upload a document with " + type.DocumentFormat.Name + " format"); return(RedirectToAction("details", new { Id = form.OrganisationId })); } if (type.UploadSize < form.File.ContentLength) { ControllerMessage.Error(this, "The file should be less than " + type.UploadSize + "kb"); return(RedirectToAction("details", new { Id = form.OrganisationId })); } // Save the file to a location var uploadPath = Server.MapPath(SystemSettings.GetStringValue("DocumentPath")); form.File.SaveAs(uploadPath + fileName); Document document = new Document { Id = Guid.NewGuid(), TypeId = type.Id, Name = fileName, Path = fileName, Size = form.File.ContentLength, CreatedBy = User.Identity.Name, CreatedDate = DateTime.Now }; db.Documents.Add(document); o.Documents.Add(document); db.SaveChanges(); ControllerMessage.Success(this, "Document uploaded!"); return(RedirectToAction("details", new { Id = o.Id })); } ControllerMessage.Error(this, "Fill form properly!"); return(RedirectToAction("details", new { Id = ViewModel.OrganisationDocumentForm.OrganisationId })); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); ControllerMessage.Error(this, "System Error"); return(RedirectToAction("index")); } }
public ActionResult Create(OrganisationViewModel ViewModel) { try { // TODO: Add insert logic here if (ModelState.IsValid) { var form = ViewModel.OrganisationForm; Organisation organisation = new Organisation { Id = Guid.NewGuid(), Name = form.Name, RegistrarId = form.RegistrarId, RCNumber = form.RCNumber, TIN = form.TIN, Website = form.Website, RegistrationYear = form.RegistrationYear, Status = Guid.Parse("2B2E6D31-D826-4153-ABBD-16E366D4EEFC"), CreatedBy = User.Identity.Name, CreatedDate = DateTime.Now }; db.Organisations.Add(organisation); var user = db.AspNetUsers.Where(x => x.UserName == User.Identity.Name).FirstOrDefault(); user.Organisations.Add(organisation); var addressForm = form.AddressForm; var addressType = db.AddressTypes.FirstOrDefault(); Address address = new Address { Id = Guid.NewGuid(), Street = addressForm.Street, LGAId = addressForm.LGAId, PhoneNumber = addressForm.PhoneNumber, AltPhoneNumber = addressForm.AltPhoneNumber, PostalCode = addressForm.PostalCode, Email = addressForm.Email, AddressTypeId = addressType.Id, CreatedBy = User.Identity.Name, CreatedDate = DateTime.Now }; address.Organisations.Add(organisation); db.Addresses.Add(address); db.SaveChanges(); ControllerMessage.Success(this, "Company detail saved!"); return(RedirectToAction("details", new { Id = organisation.Id })); } ControllerMessage.Error(this, "Invalid form submission!"); return(RedirectToAction("Index")); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); ControllerMessage.Error(this, "System error! Contact us if this is persistance"); return(RedirectToAction("Index")); } }