public ActionResult UpdateAccount(VMAccount Account) { try { if (ModelState.IsValid) { tblUser user = Session[WebUtil.CURRENT_USER] as tblUser; if (!(user != null)) { return(RedirectToAction("RedirectToLogin", "user")); } tblAccount Table = (Account).TotblAccount(); Table.CompanyId = user.CompanyId; Table.ModifiedBy = user.Id; Table.ModifiedDate = DateTime.Now; new AccountHandler().UpdateAccount(Account.Id, Table); return(JavaScript("showMessage('success', 'Account updated Successfully','bottom-right','Account', 'Manage')")); } else { return(JavaScript("showMessage('error', 'All fields are required, Please try again','bottom-right','Account', 'Manage')")); } } catch (Exception ex) { return(JavaScript("showMessage('error', 'Failed to update Account, Please Contact to Administrator','bottom-right','Account', 'Manage')")); } }
public CDataSource(IClientDataSource client, System.Windows.Threading.Dispatcher guiDisp, string dbHost, long dbPort, List <int> lstStockExchId, List <ModelStockExchState> stockExchStates, List <ModelDBCon> lstConfDBCon) : base(client, guiDisp) { _client = client; _dbHost = dbHost; _dbPort = dbPort; _dispatcher = guiDisp; _lstStockExh = lstStockExchId; _lstModelDBCon = lstConfDBCon; //_dispatcher = System.Windows.Threading.Dispatcher.CurrentDispatcher; VMTotalsInstance = new VMTotals(_modelTotals); CollVMServers = new ObservableCollection <VMServer>(); CollVMDBCon = new ObservableCollection <VMDBCon>(); VMAccount = new VMAccount(); _stockExchStates = stockExchStates; CollVMStockExchId = new ObservableCollection <VMStockExch>(); _lstStockExh.ForEach(elStockExchId => CollVMStockExchId.Add( new VMStockExch { StockExchId = elStockExchId, StockExchName = _client.GetStockExchName(elStockExchId) } )); }
public static VMAccount ToVMAccount(this ORViewAccountData entity) { VMAccount model = new VMAccount(); model.Id = entity.Id; model.AccountName = entity.AccountName; model.Description = entity.Description; model.Source = entity.Source; return(model); }
public static tblAccount TotblAccount(this VMAccount model) { tblAccount table = new tblAccount(); table.Id = model.Id; table.AccountName = model.AccountName; table.Description = model.Description; table.Source = model.Source; return(table); }
public ActionResult Edit(VMAccount vm) { if (vm.TypeId == null) { ViewBag.Error = "An Account Type must be selected."; return(View("Edit", vm)); } if (vm.OwnerId == null) { ViewBag.Error = "An Account Owner must be selected."; return(View("Edit", vm)); } using (ISession session = Hook.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { var AccountType = session.Get <VMAccountType>(vm.TypeId); if (AccountType == null) { ViewBag.Error = $"No such Account Type with Id {vm.TypeId} was found."; return(View("Edit", vm)); } var Person = session.Get <VMPerson>(vm.OwnerId); if (AccountType == null) { ViewBag.Error = $"No such Person with Id {vm.OwnerId} was found."; return(View("Edit", vm)); } vm.SetType(AccountType); vm.Person = Person; vm.CreationDate = DateTime.Today; session.SaveOrUpdate(vm); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); ViewBag.Error = e.Message; return(View("Edit", vm)); } } } return(RedirectToAction("Index")); }
public ActionResult AddAccount(VMAccount Account) { try { if (ModelState.IsValid) { if (Account.AccountName == "Initial Cash") { return(JavaScript("showMessage('error', 'Please Change Your Account Name','bottom-right','Account', 'Manage')")); } bool flag = false; List <string> NamesOfAccounts = new AccountHandler().GetAllAccountNames(); foreach (var item in NamesOfAccounts) { if (Account.AccountName == item) { flag = true; break; } } if (flag == true) { return(JavaScript("showMessage('error', 'Account name already exist','bottom-right','Account', 'Manage')")); } else { tblUser user = Session[WebUtil.CURRENT_USER] as tblUser; if (!(user != null)) { return(RedirectToAction("RedirectToLogin", "user")); } tblAccount Table = (Account).TotblAccount(); Table.CompanyId = user.CompanyId; Table.CreatedBy = user.Id; Table.CreatedDate = DateTime.Now; new AccountHandler().AddAccount(Table); return(JavaScript("showMessage('success', 'Account added Successfully','bottom-right','Account', 'Manage')")); } } else { return(JavaScript("showMessage('error', 'All fields are required, Please try again','bottom-right','Account', 'Manage')")); } } catch (Exception ex) { return(JavaScript("showMessage('error', 'Failed to Add Account, Please Contact to Administrator','bottom-right','Account', 'Manage')")); } }
public ActionResult Edit(VMAccount vm) { using (ISession session = Hook.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { try { session.SaveOrUpdate(vm); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); return(View()); } } return(RedirectToAction("Index")); } }
public IHttpActionResult InsertAccountData(VMAccount model) { if (!IsRep && (model.RepId == null || model.RepId <= 0)) { List <dynamic> errorList = new List <dynamic>(); if (!HasRight(new string[] { "RDREPGRPALL" })) { errorList.Add(new { Message = "You do not have right to read repgroup" }); } if (!HasRight(new string[] { "WRREP" })) { errorList.Add(new { Message = "You do not have right to create rep" }); } if (errorList != null && errorList.Count <= 0) { errorList.Add(new { Message = "RepGroup and Rep are required" }); } return(Ok <dynamic>(new { Status = HttpStatusCode.PreconditionFailed, ResponseMessage = errorList })); } var repository = new RepositoryAccount(); var response = new DataResponse(); if (ModelState.IsValid) { var entityAccount = new EntityAccount { EnrolledDate = model.EnrolledDate, IsActive = model.IsActive, LeadSourceId = model.LeadSourceId, LeadServiceIntrest = model.ServiceInterest, RepGroupId = model.RepGroupId, RepId = model.RepId, IsConverted = true, ServiceIds = model.EnrolledServices }; entityAccount.Practice = new EntityPractice { //Fax = model.Fax, ReportDeliveryEmail = model.ReportDeliveryEmail, ReportDeliveryFax = model.ReportDeliveryFax, Name = model.PracticeName, SpecialityTypeId = model.SpecialityTypeId, ContactPreferenceId = model.MethodOfContact, Address = new List <EntityPracticeAddress> { new EntityPracticeAddress { Id = model.AddressId ?? 0, AddressIndex = -1, City = model.City, Line1 = model.PracticeAddressLine1, Line2 = model.PracticeAddressLine2, AddressTypeId = 1, StateId = model.StateId ?? 0, Zip = model.Zip, Fax = model.Fax, Phone = new List <EntityPracticePhone> { new EntityPracticePhone { PhoneNumber = model.PhoneNumber, Extension = model.PhoneExtension } }, AddressId = model.AddressId ?? 0, ManagerName = model.ManagerName, ManagerEmail = model.ManagerEmail, ManagerPhone = model.ManagerPhone, BillingContact = model.BillingContact, BillingContactEmail = model.BillingContactEmail, BillingContactPhone = model.BillingContactPhone, officedayshrs = model.WorkingHours, } }, Contact = new List <EntityPracticeContact> { new EntityPracticeContact { BillingContact = model.BillingContact, BillingContactEmail = model.BillingContactEmail, BillingContactPhone = model.BillingContactPhone, ManagerName = model.ManagerName, ManagerPhone = model.ManagerPhone, ManagerEmail = model.ManagerEmail, officedayshrs = model.WorkingHours, AddressId = model.AddressId ?? 0 } } }; var specialities = new List <EntityPracticeSpeciality>(); entityAccount.Practice.Specialities = new List <EntityPracticeSpeciality>(); entityAccount.PracticeTypeId = model.SpecialityTypeId == 0 ? null : model.SpecialityTypeId; if (model.SpecialityTypeId == 1) { specialities.Add(new EntityPracticeSpeciality { PracticeSpecialityId = model.SpecialityId ?? 0 }); } else if (model.SpecialityTypeId == 2 && model.SpecialityIds != null && model.SpecialityIds.Count() > 0) { foreach (string sId in model.SpecialityIds) { specialities.Add(new EntityPracticeSpeciality { PracticeSpecialityId = int.Parse(sId) }); } } else if (model.SpecialityTypeId == 3 && !string.IsNullOrEmpty(model.NewSpectialityName)) { entityAccount.Practice.SpecialityType = model.NewSpectialityName; } if (specialities.Count > 0) { entityAccount.Practice.Specialities = specialities; } if (model.Locations != null) { var addressList = new List <EntityPracticeAddress>(); var contactList = new List <EntityPracticeContact>(); model.Locations.ToList().ForEach(a => addressList.Add(new EntityPracticeAddress { Id = a.AddressId ?? 0, AddressIndex = a.AddressIndex.Value, Line1 = a.AddressLine1, Line2 = a.AddressLine2, City = a.City, AddressTypeId = 2, StateId = a.StateId ?? 0, Zip = a.Zip, Fax = a.Fax, Phone = new List <EntityPracticePhone> { new EntityPracticePhone { PhoneNumber = a.PhoneNumber, Extension = a.Extension } }, AddressId = a.AddressId ?? 0, ManagerName = a.ManagerName, ManagerEmail = a.ManagerEmail, ManagerPhone = a.ManagerPhone, BillingContact = a.BillingContact, BillingContactEmail = a.BillingContactEmail, BillingContactPhone = a.BillingContactPhone, officedayshrs = a.WorkingHours, })); if (addressList.Count > 0) { entityAccount.Practice.Address = entityAccount.Practice.Address.Concat(addressList); } entityAccount.Practice.Address.ToList().ForEach(a => contactList.Add(new EntityPracticeContact { AddressId = a.AddressId, ManagerName = a.ManagerName, ManagerEmail = a.ManagerEmail, ManagerPhone = a.ManagerPhone, BillingContact = a.BillingContact, BillingContactEmail = a.BillingContactEmail, BillingContactPhone = a.BillingContactPhone, officedayshrs = a.officedayshrs, })); if (contactList.Count > 0) { entityAccount.Practice.Contact = contactList; } } if (model.Providers != null) { var isMultipleProviders = model.Providers.GroupBy(a => a.NPI).Any(a => a.Count() > 1); if (isMultipleProviders) { return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = new { Key = "NPI", Message = "NPI is Repeating" } })); } var providerList = new List <EntityProvider>(); model.Providers.ForEach(a => providerList.Add( new EntityProvider { Id = a.Id ?? 0, DegreeId = a.DegreeId ?? 0, FirstName = a.FirstName, LastName = a.LastName, MiddleName = a.MiddleName, NPI = a.NPI, AddressIndex = a.Location != null ? (a.Location.AddressIndex == null ? -1 : a.Location.AddressIndex.Value) : -1, Address = a.Location != null ? new EntityProviderAddress { Id = a.Location.AddressId == null ? 0 : a.Location.AddressId.Value, City = a.Location.City, Line1 = a.Location.AddressLine1, Line2 = a.Location.AddressLine2, AddressTypeId = 2, StateId = a.Location.StateId.Value, Zip = a.Location.Zip, Fax = a.Location.Fax, ManagerName = a.Location.ManagerName, Phone = a.Location == null ? null : new List <EntityPracticePhone> { new EntityPracticePhone { PhoneNumber = a.Location.PhoneNumber, Extension = a.Location.Extension } } } : null })); if (providerList.Count > 0) { entityAccount.Practice.Providers = providerList; } } entityAccount.UpdatedBy = entityAccount.CreatedBy = entityAccount.CurrentUserId = CurrentUser.Id; entityAccount.BusinessId = CurrentUser.BusinessId; entityAccount.CreatedByName = string.Format("{0} {1}", CurrentUser.FirstName, CurrentUser.LastName); if (model.Id > 0) //Update { entityAccount.Id = model.Id ?? 0; response = repository.Update(entityAccount); } else { if (model.LeadId > 0) //Converted from Lead { entityAccount.LeadId = model.LeadId; response = repository.ConvertToAccount(entityAccount); } else //New account { response = repository.Insert(entityAccount); } if (response.Id != null) { string services = string.Empty, providers = string.Empty, practiceAddress = string.Empty; if (entityAccount.ServiceIds != null) { var ids = ((IEnumerable <string>)entityAccount.ServiceIds).Select(a => Convert.ToInt32(a)).ToArray(); services = string.Join(", ", new RepositoryLookups().GetServicesById(ids)); } foreach (var item in entityAccount.Practice.Providers) { providers = providers + item.FirstName + " " + item.LastName + " (" + item.NPI + ") <br />"; } var primaryAddress = entityAccount.Practice.Address.First(); var stateName = new RepositoryLookups().GetAllStates().Model.List.Where(a => a.Id == primaryAddress.StateId).First().Value; practiceAddress = string.Format("{0}, {1}, {2}, {3}, {4}", primaryAddress.Line1, primaryAddress.Line2, primaryAddress.City, stateName, primaryAddress.Zip); EntityGroupManagerDetails RepModel = repository.RepDetailsByAccountId(response.Id).Model; EmailNotification emailNotify = new EmailNotification { PracticeName = model.PracticeName, PracticeAddress = practiceAddress, Providers = providers, Services = services, RepFirstName = RepModel.RepFirstName, RepMiddleName = RepModel.RepMiddleName, RepLastName = RepModel.RepLastName, RepEmail = RepModel.RepEmail, Managers = RepModel.Managers, CurrentUserFirstName = CurrentUser.FirstName, CurrentUserLastName = CurrentUser.LastName, RootPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, ReturnUrl = ConfigurationManager.AppSettings["BaseUrl"], }; NewAccountEmailNotification(emailNotify); } } } else { var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new { Key = s.Key.Split('.').Last(), Message = s.Value.Errors[0].ErrorMessage }); return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList })); } return(Ok <DataResponse>(response)); }