public ActionResult Edit(OrganisationAddressModel editModel)
        {
            sw.AddressBook memberBeneficiary = editModel.addressBook;
            try
            {
                if (ModelState.IsValid)
                {
                    memberBeneficiary.ModifiedBy  = User.Identity.Name;
                    memberBeneficiary.ModifedDate = DateTime.Now;

                    swdb.AddressBook.Attach(memberBeneficiary);
                    swdb.Entry(memberBeneficiary).State = EntityState.Modified;
                    //swdb.ObjectStateManager.ChangeObjectState(memberBeneficiary, EntityState.Modified);


                    swdb.SaveChanges();
                    TempData["message"] = "<b>" + memberBeneficiary.City + "</b> was Successfully Updated";
                    return(RedirectToAction("Index", new { orgID = memberBeneficiary.OrgID }));
                }

                editModel.addressType = new SelectList(swdb.AddressType, "ID", "Name", memberBeneficiary.AddressTypeId).ToList();

                return(View(editModel));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index", new { orgID = memberBeneficiary.OrgID }));
            }
        }
Esempio n. 2
0
        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 Edit(sw.OrganisationType organisationtype)
 {
     try
     {
         if (ModelState.IsValid)
         {
             organisationtype.ModifiedBy   = User.Identity.Name;
             organisationtype.ModifiedDate = DateTime.Now;
             swdb.OrganisationType.Attach(organisationtype);
             swdb.Entry(organisationtype).State = EntityState.Modified;
             // swdb.ObjectStateManager.ChangeObjectState(organisationtype, EntityState.Modified);
             swdb.SaveChanges();
             TempData["message"] = "<b>" + organisationtype.Name + "</b> was Successfully Updated";
             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 ActionResult Edit(OrganisationEditModel editModel)
        {
            try
            {
                sw.Organisation organisation = editModel.org;
                if (ModelState.IsValid)
                {
                    if (String.IsNullOrEmpty(organisation.RegNumber))
                    {
                        var applNoResp = generateEmployerNumber(organisation.Name, organisation.CommencementDate ?? DateTime.Now);
                        if (applNoResp.Key == true)
                        {
                            organisation.RegNumber = applNoResp.Value;
                        }
                    }


                    organisation.ModifiedBy   = User.Identity.Name;
                    organisation.ModifiedDate = DateTime.Now;
                    swdb.Organisation.Attach(organisation);
                    swdb.Entry(organisation).State = EntityState.Modified;
                    // swdb.ObjectStateManager.ChangeObjectState(organisation, EntityState.Modified);
                    swdb.SaveChanges();



                    if (membershipService.GetUser(organisation.RegNumber) == null)
                    {
                        MembershipUser newUser;
                        //MembershipCreateStatus status;
                        newUser = membershipService.CreateUser(organisation.RegNumber, organisation.RegNumber, organisation.ContactEmailAddress);

                        roleService.AddUserToRole(organisation.RegNumber, "Organisation Admin");

                        sw.Users user = swdb.Users.Where(x => x.UserName == organisation.RegNumber).FirstOrDefault();
                        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 Updated";
                    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.OrgID == organisation.Id).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" }));
            }
        }