Пример #1
0
        public ActionResult GetRACI(string[] contact_keys)
        {
            ViewData["RACI"] = _contactFacade.GetRACI();
            var orgResp = _orgFacade.Find(CurrentUser.User.org_key.ToString());
            var model   = new RACIViewModel();

            model.Organization = orgResp.Success ? orgResp.Result : new CoOrganization();
            model.Contacts     = GetFilterContacts(contact_keys);

            return(PartialView("RACI", model));
        }
Пример #2
0
        public async Task <ActionResult> RACI(RACIViewModel model, string[] contact_keys)
        {
            ViewData["RACI"] = _contactFacade.GetRACI();
            var orgResp = _orgFacade.Find(CurrentUser.User.org_key.ToString());

            model.Organization = orgResp.Success ? orgResp.Result : new CoOrganization();

            if (ModelState.IsValid)
            {
                var contact = new CoContact()
                {
                    ct_email           = model.NewContact.Email,
                    ct_password        = model.NewContact.Password.GetEncryptedString(),
                    ct_first_name      = model.NewContact.FirstName,
                    ct_last_name       = model.NewContact.LastName,
                    ct_phone           = model.NewContact.Phone,
                    ct_fax             = model.NewContact.Fax,
                    ct_key             = Guid.NewGuid(),
                    ct_add_user        = CurrentUser.User.ct_key.ToString(),
                    ct_activation_code = Guid.NewGuid()
                };

                try
                {
                    bool isEmail = Regex.IsMatch(model.NewContact.Email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);

                    if (!isEmail)
                    {
                        ModelState.AddModelError("NewContact.Email", "Enter valid email address.");
                        model.Contacts = GetFilterContacts(contact_keys);
                        return(PartialView(model));
                    }

                    var existingUser = _contactFacade.GetByUsername(model.NewContact.Email.Trim());

                    if (existingUser.Success)
                    {
                        ModelState.AddModelError("NewContact.Email", "This email is already registered");
                        model.Contacts = GetFilterContacts(contact_keys);
                        return(PartialView(model));
                    }
                    else
                    {
                        _contactFacade.Add(contact, CurrentUser.User.ct_key.ToString());
                        _contactFacade.Add_Contact_Org(CurrentUser.User.org_key.ToString(), contact.ct_key.ToString(), CurrentUser.User.ct_key.ToString());
                        TempData["Message"] = "New contact has been created successfully.";
                        //EmailManager.SendWelcome(contact.ct_email, string.Format("{0} {1}", contact.ct_first_name, contact.ct_last_name), contact.ct_activation_code.ToString());
                        model.NewContact = new RegisterViewModel();
                        model.Contacts   = GetFilterContacts(contact_keys);
                        return(PartialView(model));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    model.Contacts = GetFilterContacts(contact_keys);
                    return(PartialView(model));
                }
            }

            // If we got this far, something failed, redisplay form
            model.Contacts = GetFilterContacts(contact_keys);
            return(PartialView(model));
        }