示例#1
0
        public ActionResult Create(CoOrganization model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.org_add_date = DateTime.Now;
                    _organizationFacade.Add(model, string.Empty);
                }
                else
                {
                    return(View(model));
                }

                return(RedirectToAction("Index", "Organization"));
            }
            catch
            {
                return(View(model));
            }
        }
示例#2
0
        public JsonResult SaveUser_old(UserContactViewModel model, string upID)
        {
            string    currUser = CurrentUser.User.ct_key.ToString();
            CoContact contact  = new CoContact();

            if (String.IsNullOrEmpty(upID))
            {
                contact = new CoContact()
                {
                    ct_email           = model.Email,
                    ct_password        = model.Password.GetEncryptedString(),
                    ct_first_name      = model.FirstName,
                    ct_last_name       = model.LastName,
                    ct_phone           = model.Phone,
                    ct_fax             = model.Fax,
                    ct_key             = Guid.NewGuid(),
                    ct_add_user        = currUser,
                    ct_activation_code = Guid.NewGuid(),
                    ct_active          = model.IsActive? Convert.ToInt16(1) : Convert.ToInt16(0),
                }
            }
            ;
            else
            {
                var up_user = db.co_contact.Where(w => w.ct_key.ToString() == upID).FirstOrDefault();
                contact = new CoContact()
                {
                    ct_email           = model.Email,
                    ct_password        = up_user.ct_password,
                    ct_first_name      = model.FirstName,
                    ct_last_name       = model.LastName,
                    ct_phone           = model.Phone,
                    ct_fax             = model.Fax,
                    ct_key             = up_user.ct_key,
                    ct_id              = up_user.ct_id,
                    ct_add_user        = up_user.ct_add_user,
                    ct_change_user     = currUser,
                    ct_change_date     = DateTime.Now.ToString(),
                    ct_add_date        = up_user.ct_add_date.HasValue ? up_user.ct_add_date.Value.ToString() : "",
                    ct_activation_code = up_user.ct_activation_code.HasValue ?
                                         up_user.ct_activation_code.Value : Guid.NewGuid(),
                    ct_active = model.IsActive ? Convert.ToInt16(1) : Convert.ToInt16(0),
                };
            }
            try
            {
                var result = orgService.GetWhere($"org_domain='{model.OrgDomain.Trim()}'");

                if ((result == null || (result != null && result.Count == 0)) &&
                    string.IsNullOrWhiteSpace(model.OrgName))
                {
                    return(Json(new
                    {
                        status = "error",
                        msg = "Enter valid organization name."
                    }, JsonRequestBehavior.AllowGet));
                }

                var existingUser = contactService.GetByUsername(model.Email.Trim());

                if (existingUser.Success && String.IsNullOrEmpty(upID))
                {
                    return(Json(new
                    {
                        status = "error",
                        msg = "This email is already registered."
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    CoOrganization org = null;

                    if (result.Count > 0)
                    {
                        org = result[0];
                    }
                    else
                    {
                        var org_resp = orgService.Add(new CoOrganization
                        {
                            org_add_date   = DateTime.Now,
                            org_key        = Guid.NewGuid(),
                            org_legal_name = model.OrgName.Trim(),
                            org_domain     = model.OrgDomain,
                            org_add_user   = currUser
                        }, currUser);

                        if (org_resp.Success)
                        {
                            org = org_resp.Result;
                            var response = contactService.Add(contact, currUser);

                            if (response.Success)
                            {
                                contactService.Add_Contact_Org(org.org_key.ToString(), contact.ct_key.ToString(), currUser);
                                // TempData["Message"] = "You have been registered successfully. Please check your email to activate account.";
                                // EmailManager.SendWelcome(contact.ct_email, string.Format("{0} {1}", contact.ct_first_name, contact.ct_last_name), contact.ct_activation_code.ToString());

                                return(Json(new
                                {
                                    status = "Done",
                                    msg = "You Added User successfully."
                                }, JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                return(Json(new
                                {
                                    status = "error",
                                    msg = "Could not register you. Please contact support."
                                }, JsonRequestBehavior.AllowGet));
                            }
                        }
                        else
                        {
                            return(Json(new
                            {
                                status = "error",
                                msg = "OrgName: Could not find organization."
                            }, JsonRequestBehavior.AllowGet));
                        }
                    }

                    return(Json(new
                    {
                        status = "Done",
                        msg = "You Added User successfully."
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    status = "error",
                    msg = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }