private bool Save(Resources row) { try { row.ModifiedDate = DateTime.Now; row.ModifiedBy = User.Identity.Name; //If it's a new record, just attach it to the DataContext if (row.Id == 0) { swdb.Resources.Add(row); } else { // We're updating an existing record, but it's not attached to // this data context, so attach it and detect the changes swdb.Resources.Attach(row); swdb.Entry(row).State = EntityState.Modified; //ObjectStateEntry objectStateEntry = db.ObjectStateManager.GetObjectStateEntry(row); //foreach (string str in from fm in objectStateEntry.CurrentValues.DataRecordInfo.FieldMetadata select fm.FieldType.Name) //{ // objectStateEntry.SetModifiedProperty(str); //} } swdb.SaveChanges(); return(true); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); TempData["message"] = ex.Message; return(false); } }
public ActionResult Create(OrganisationAddressModel editModel) { sw.AddressBook memberBeneficiary = editModel.addressBook; try { if (ModelState.IsValid) { memberBeneficiary.ModifiedBy = User.Identity.Name; memberBeneficiary.ModifedDate = DateTime.Now; swdb.AddressBook.Add(memberBeneficiary); swdb.SaveChanges(); TempData["message"] = "<b>" + memberBeneficiary.Street + "</b> was Successfully Saved"; return(RedirectToAction("Index", new { orgID = memberBeneficiary.OrgID })); } sw.Organisation member = swdb.Organisation.Where(x => x.Id == editModel.addressBook.OrgID).FirstOrDefault(); editModel.org = member; editModel.addressType = new SelectList(swdb.AddressType, "ID", "Name").ToList(); return(View(editModel)); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); TempData["message"] = Settings.Default.GenericExceptionMessage; return(RedirectToAction("Index", new { orgID = memberBeneficiary.OrgID })); } }
public KeyValuePair <bool, string> SendNotificationToPerson(string sender, string receiver, string subject, string message, DateTime timestamp) { KeyValuePair <bool, string> response = new KeyValuePair <bool, string>(); try { sw.Notification row = new sw.Notification { Sender = sender, Receiver = receiver, Subject = subject, Message = message, NotificationStatusId = 0, NotificationTypeId = 3, SentDate = timestamp, ModifiedDate = timestamp, ModifiedBy = sender }; swdb.Notification.Add(row); swdb.SaveChanges(); //if (Save(row)) //{ // response = new KeyValuePair<bool, string>(true, "Successfully Sent!"); //} } catch (Exception ex) { response = new KeyValuePair <bool, string>(false, ex.Message); } return(response); }
public ActionResult EditProfile(ProfileEditModel row) { try { if (ModelState.IsValid) { sw.UserDetails userDetails = new sw.UserDetails(); userDetails = row.userDetails; userDetails.ModifiedBy = User.Identity.Name; userDetails.ModifiedDate = DateTime.Now; var record = (from x in swdb.UserDetails where x.UserId == userDetails.UserId select x).FirstOrDefault(); if (record != null) { record.FirstName = userDetails.FirstName; record.LastName = userDetails.LastName; record.MiddleName = userDetails.MiddleName; record.PhoneNumber = userDetails.PhoneNumber; swdb.SaveChanges(); } else { swdb.UserDetails.Add(userDetails); swdb.SaveChanges(); } TempData["message"] = "Account details was saved successfully"; return(RedirectToAction("EditProfile", new { UserId = row.userDetails.UserId })); } else { return(RedirectToAction("EditProfile", new { UserId = row.userDetails.UserId })); } } catch (Exception ex) { //ToDo: Log with Elmah Elmah.ErrorSignal.FromCurrentContext().Raise(ex); TempData["message"] = Settings.Default.GenericExceptionMessage; return(RedirectToAction("Index", "Home", new { area = "Admin" })); } }
public ActionResult Create(sw.OrganisationType organisationtype) { try { if (ModelState.IsValid) { organisationtype.ModifiedBy = User.Identity.Name; organisationtype.ModifiedDate = DateTime.Now; swdb.OrganisationType.Add(organisationtype); swdb.SaveChanges(); TempData["message"] = "<b>" + organisationtype.Name + "</b> was Successfully Created"; return(RedirectToAction("Index")); } return(View(organisationtype)); } catch (Exception ex) { // Log with Elmah TempData["message"] = Settings.Default.GenericExceptionMessage; return(RedirectToAction("Index", "Home", new { area = "Admin" })); } }
public bool Save(sw.Notification row) { try { swdb.Notification.Add(row); swdb.SaveChanges(); Send(row.Receiver); return(true); } catch (Exception ex) { return(false); } }
public ActionResult Create(OrganisationEditModel editModel) { try { sw.Organisation organisation = editModel.org; if (NameExist(organisation.Name)) { ModelState.AddModelError("Name", "Employer Name Already exist"); } if (ModelState.IsValid) { var applNoResp = generateEmployerNumber(organisation.Name, organisation.CommencementDate ?? DateTime.Now); if (applNoResp.Key == true) { organisation.RegNumber = applNoResp.Value; } organisation.StatusID = 1; organisation.BranchID = getBranchID(); organisation.ModifiedBy = User.Identity.Name; organisation.ModifiedDate = DateTime.Now; organisation.CreatedBy = User.Identity.Name; organisation.DateCreated = DateTime.Now; swdb.Organisation.Add(organisation); swdb.SaveChanges(); MembershipUser newUser; //MembershipCreateStatus status; newUser = membershipService.CreateUser(organisation.RegNumber, organisation.RegNumber, organisation.ContactEmailAddress); roleService.AddUserToRole(organisation.RegNumber, "Organisation Admin"); // organisation.Users.Add(newUser); sw.Users user = swdb.Users.FirstOrDefault(x => x.UserName == organisation.RegNumber); organisation.Users.Add(user); swdb.SaveChanges(); //int[] acnts = editModel.SelectedAcountTypes; //if (acnts != null) //{ // foreach (int account in acnts) // { // OrganisationPortfolio orgPort = db.OrganisationPortfolio.Where(x => x.OrgID == organisation.Id && x.AccountTypeID == account).FirstOrDefault(); // if (orgPort == null) // { // OrganisationPortfolio detail = new OrganisationPortfolio(); // detail.AccountTypeID = account; // detail.OrgID = organisation.Id; // detail.AccountState = 1; // detail.LastPayment = DateTime.Now; // detail.ModifiedBy = User.Identity.Name; // detail.ModifiedDate = DateTime.Now; // detail.TotalPayments = 0; // detail.TotalOverPaid = 0; // detail.TotalPenalty = 0; // db.OrganisationPortfolio.AddObject(detail); // db.SaveChanges(); // } // } //} TempData["message"] = "<b>" + organisation.Name + "</b> was Successfully Created"; return(RedirectToAction("Index")); } editModel.orgTypes = new SelectList(swdb.OrganisationType, "Id", "Name", organisation.OrganisationTypeId).ToList(); //editModel.OfficeBranch = new SelectList(db.OfficeBranch, "Id", "BranchName", organisation.BranchID).ToList(); //editModel.accountTypes = db.AccountType.ToList(); //editModel.SelectedAcountTypes = db.OrganisationPortfolio.Where(x => x.ID == -1).Select(x => x.AccountTypeID ?? 0).ToArray(); return(View(editModel)); } catch (Exception ex) { // Log with Elmah Elmah.ErrorSignal.FromCurrentContext().Raise(ex); TempData["message"] = Settings.Default.GenericExceptionMessage; return(RedirectToAction("Index", "Home", new { area = "Admin" })); } }
public virtual ActionResult CreateRole(string roleName, [DefaultValue(0)] int Id) { JsonResponse response = new JsonResponse(); if (string.IsNullOrEmpty(roleName)) { response.Success = false; response.Message = "You must enter a role name."; response.CssClass = "red"; return(Json(response)); } try { sw.Organisation organisation; roleService.CreateRole(roleName); if (System.Web.Security.Roles.IsUserInRole(Settings.Default.OrganisationAdminRole) && !System.Web.Security.Roles.IsUserInRole("ADMINISTRATOR")) { GetOrganisation objGetOrganisation = new GetOrganisation(); MembershipUser user = Membership.GetUser(User.Identity.Name); organisation = objGetOrganisation.byUser(user); if (organisation == null) { throw new Exception("Could not find Organisation"); } Id = organisation.Id; } if (Request.IsAjaxRequest()) { if (Id != 0) { //db.ContextOptions.LazyLoadingEnabled = false; swdb.Configuration.LazyLoadingEnabled = false; organisation = (swdb.Organisation.Include("Roles").Where(x => x.Id == Id)).FirstOrDefault(); if (organisation == null) { throw new Exception("Could not find Organisation"); } var role = (from r in swdb.Roles where r.RoleName == roleName select r).FirstOrDefault(); //organisation.Roles.Remove(role); organisation.Roles.Add(role); swdb.SaveChanges(); } response.Success = true; response.Message = "Role created successfully!"; response.CssClass = "green"; return(Json(response)); } return(RedirectToAction("Index")); } catch (Exception ex) { if (Request.IsAjaxRequest()) { response.Success = false; response.Message = ex.Message; response.CssClass = "red"; return(Json(response)); } ModelState.AddModelError("", ex.Message); } return(RedirectToAction("Index")); }
public virtual ActionResult CreateUser(RegisterViewModel model) { try { if (ModelState.IsValid) { sw.Organisation organisation = new sw.Organisation(); //var password = Membership.GeneratePassword(8, 0); // model.Password = password; //model.ConfirmPassword = password; string message = "Welcome <br><br>Find below your account details<br><br>Username: "******" <br>Password: "******"New Account Details"; MembershipUser newUser; MembershipCreateStatus status; newUser = membershipService.CreateUser(model.UserName, model.Password, model.Email, model.SecretQuestion, model.SecretAnswer, model.Approve, out status); if (newUser == null) { var msg = GetErrorMessage(status); TempData["message"] = "alert-danger"; TempData["message"] = msg; return(RedirectToAction("Index")); } else { if (System.Web.Security.Roles.IsUserInRole(Settings.Default.OrganisationAdminRole) && !System.Web.Security.Roles.IsUserInRole("Administrator")) { GetOrganisation objGetOrganisation = new GetOrganisation(); MembershipUser user = Membership.GetUser(User.Identity.Name); organisation = objGetOrganisation.byUser(user); if (organisation == null) { throw new Exception("Could not find Organisation"); } model.Id = organisation.Id; } if (model.Id != 0) { organisation = (from o in swdb.Organisation where o.Id == model.Id select o).FirstOrDefault(); if (organisation == null) { throw new Exception("Could not find Organisation"); } model.objOrganisation = organisation; sw.Users user = swdb.Users.Where(x => x.UserId == (Guid)newUser.ProviderUserKey).FirstOrDefault(); organisation.Users.Add(user); swdb.SaveChanges(); ///Send Email to New User Account//// // @utility.SendEmailToPerson(Settings.Default.EmailReplyTo, newUser.Email, subject, message, DateTime.Now, null, null, null); return(RedirectToAction("GrantRolesToUser", new { username = newUser.UserName, Id = model.Id })); } ///Send Email to New User Account//// // @utility.SendEmailToPerson(Settings.Default.EmailReplyTo, newUser.Email, subject, message, DateTime.Now, null, null, null); return(routeHelpers.Actions.GrantRolesToUser(newUser.UserName)); //RedirectToAction("GrantRolesToUser",new{UserName = '', Id = ''}) } } } catch (Exception ex) { //Elmah.ErrorSignal.FromCurrentContext().Raise(ex); TempData["message"] = Settings.Default.GenericExceptionMessage; return(RedirectToAction("Index", "Home", new { area = "Admin" })); } return(View()); }