コード例 #1
0
ファイル: SingUpController.cs プロジェクト: edalonzoh90/Egulf
        public ActionResult ValidateEmail(string email)
        {
            PersonServices PersonServ    = new PersonServices();
            bool           ValidateEmail = true;
            int?           UserId        = (SessionWeb.User != null) ? SessionWeb.User.UserId : null;

            if (UserId != null && UserId > 0)
            {
                UserPersonModel UserCurrentData = PersonServ.getFirstUserPerson(new UserPersonModel()
                {
                    UserId = UserId
                });
                if (email.ToUpper().Trim() == UserCurrentData.Email.ToUpper().Trim())
                {
                    ValidateEmail = false;
                }
            }

            if (ValidateEmail)
            {
                var result = PersonServ.ValidateExistingEmail(email);
                if (result.Status == Status.Warning)
                {
                    Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                    Response.StatusDescription = EGULF.App_LocalResources.SingUp.MsgEmailExisting;
                }
            }
            return(Json(new RequestResult <object>()
            {
                Status = Status.Success
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public ActionResult Create(CompanyModel data)
        {
            try
            {
                if (HasCompany())
                {
                    return(RedirectToAction("Index"));
                }

                if (ModelState.IsValid)
                {
                    PersonServices PersonServ = new PersonServices();
                    var            userId     = (int)SessionWeb.User.UserId;
                    var            person     = PersonServ.getFirstUserPerson(new UserPersonModel()
                    {
                        UserId = userId
                    }).ToPerson();
                    CompanyServices cs = new CompanyServices();
                    CompanyModel    cm = new CompanyModel()
                    {
                        CompanyName = data.CompanyName,
                        RFC         = data.RFC,
                        Address     = data.Address,
                        PhoneNumber = data.PhoneNumber,
                        Email       = data.Email
                    };
                    var result = cs.AddCompany(cm, person);
                    if (result.Status != Status.Success)
                    {
                        throw new Exception(string.Format("{0}: {1}", localResource.txt_company_error_saved, result.Message));
                    }
                    SessionWeb.User.CompanyId = ((CompanyModel)result.Data).CompanyId;
                    InvitationCompanyServices invServ = new InvitationCompanyServices();
                    foreach (var i in UserPerson.InvitationsCompanies)
                    {
                        i.Status = 2;
                        invServ.InsUpd(i);
                    }
                    return(Json(result));
                }
                return(Json(new RequestResult <object>()
                {
                    Status = Status.Error, Message = localResource.txt_company_error_saved
                }));
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;

                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
                //return Json(new RequestResult<object>() { Status = Status.Error, Message = ex.Message });
            }
        }
コード例 #3
0
        public JsonResult GetUserProfile(int userId)
        {
            try
            {
                RequestResult <UserPersonModel> response = new RequestResult <UserPersonModel>();
                PersonServices PersonServ = new PersonServices();
                response.Data = PersonServ.getFirstUserPerson(new UserPersonModel()
                {
                    UserId = userId
                });

                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new RequestResult <object>()
                {
                    Status = Status.Error, Message = ex.Message
                }));
            }
        }
コード例 #4
0
        public ActionResult DeleteInvivtation(int id, string email)
        {
            try
            {
                PersonServices persnServ = new PersonServices();
                var            p         = persnServ.getFirstUserPerson(new UserPersonModel()
                {
                    Email = email
                });
                InvitationCompanyServices cs = new InvitationCompanyServices();
                InvitationCompanyModel    cm = new InvitationCompanyModel()
                {
                    CompanyInvitationId = id,
                    From = p.PersonId
                };
                PagerModel pager       = new PagerModel(0, 100, "", "");
                var        invitations = cs.Get(pager, cm);
                cm = invitations.Find(x => x.To == p.PersonId);
                var result = (p != null && p.CompanyId == UserCompanyId) ? cs.RemoveCompanyInvitation(cm, p.ToPerson()) : cs.Del(cm);
                if (p != null && cm.Status != 2)
                {
                    SendNotificationsInvite(p.PersonId, 3);
                }
                if (result.Status != Status.Success)
                {
                    throw new Exception(string.Format("{0}: {1}", localResource.txt_error_remove_invitation, result.Message));
                }
                return(Json(result));
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;

                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #5
0
        public ActionResult Invitate(string mails)
        {
            try
            {
                if (string.IsNullOrEmpty(mails.Trim()))
                {
                    return(Json(new RequestResult <object>()
                    {
                        Status = Status.Warning, Message = localResource.txt_invitation_empty
                    }));
                }

                InvitationCompanyServices invServ   = new InvitationCompanyServices();
                PersonServices            persnServ = new PersonServices();
                string[] mailsS = mails.Split(new Char[] { ',' });
                RequestResult <object> result = new RequestResult <object>()
                {
                    Status = Status.Success
                };
                string mailsNoSend = string.Empty;

                foreach (var mail in mailsS)
                {
                    var mailT = mail.Trim();
                    //Enviar invitación
                    if (!HasInvitation(mailT, UserCompanyId))
                    {
                        //si tiene CUENTA
                        UserPersonModel p = null;
                        if ((p = persnServ.getFirstUserPerson(new UserPersonModel()
                        {
                            Email = mailT
                        })) != null)
                        {
                            if (p.CompanyId != null)
                            {
                                mailsNoSend += "," + mail;
                                continue;
                            }

                            SendNotificationsInvite(p.PersonId, 2);
                        }
                        SendMailInvitation(mailT);
                        result = invServ.InsUpd(new InvitationCompanyModel()
                        {
                            CompanyId = UserCompanyId,
                            From      = UserPerson.PersonId,
                            To        = p == null ? null : p.PersonId,
                            CreatedAt = DateTime.Now,
                            Status    = 0,
                            Email     = mailT
                        });
                    }
                    if (HasRejectedInvitation)
                    {
                        mailsNoSend += "," + mail;
                    }
                }
                if (result == null || result.Status != Status.Success)
                {
                    throw new Exception(string.Format("{0}: {1}", localResource.txt_error_invite, result.Message));
                }
                if (!string.IsNullOrEmpty(mailsNoSend))
                {
                    return(Json(new RequestResult <object>()
                    {
                        Status = Status.Warning, Message = string.Format(localResource.txt_invitation_has_company, mailsNoSend.Substring(1))
                    }));
                }

                return(Json(result));
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;

                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }