예제 #1
0
        public ActionResult AddPOC(BusinessContactViewModel viewModel)
        {
            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                var loggedOnUserId = LoggedOnReadOnlyUser?.Id ?? Guid.Empty;
                var admin          = MembershipService.Get(loggedOnUserId);
                var settings       = SettingsService.GetSettings();
                var business       = _businessService.Get(viewModel.Id);

                var newContact = new BusinessContact
                {
                    FirstName    = viewModel.FirstName,
                    LastName     = viewModel.LastName,
                    PrimaryPhone = viewModel.PrimaryPhoneNumber,
                    Email        = viewModel.Email,
                    Business     = business
                };

                try
                {
                    _businessService.AddBusinessContact(newContact);
                    _businessService.AdminBusinessContactAdded(newContact, admin);
                    unitOfWork.Commit();
                    TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel
                    {
                        Message     = "Business Contact Added.",
                        MessageType = GenericMessages.success
                    };
                    return(RedirectToAction("POC", "AdminBusiness", new { id = business.Id }));
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    //LoggingService.Error(ex);
                    TempData[AppConstants.MessageViewBagName] = new AdminGenericMessageViewModel
                    {
                        Message     = "Adding a business contact failed.",
                        MessageType = GenericMessages.danger
                    };
                }

                return(RedirectToAction("POC", "AdminBusiness", new { id = business.Id }));
            }
        }