Пример #1
0
        public Organization AddNewOrganization(CreateOrganization organizationBasic, string UserName)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
            }
            var newOrg = CreatEmptyOrganization();

            newOrg.OrganizationId    = CurrenUser;
            newOrg.OrganizationName  = organizationBasic.OrganizationName;
            newOrg.EOrganizationName = ConvertToUnSign.Convert(organizationBasic.OrganizationName);
            newOrg.Introduction      = organizationBasic.Introduction;
            newOrg.LogoUrl           = organizationBasic.LogoUrl;
            newOrg.Phone             = organizationBasic.Phone;
            newOrg.Email             = organizationBasic.Email;
            newOrg.Address           = organizationBasic.Address;
            newOrg.IsVerify          = false;
            newOrg.IsActive          = true;
            newOrg.Point             = 0;
            newOrg.CreatedDate       = DateTime.Now;

            using (var db = new Ws_DataContext())
            {
                db.Organizations.Add(newOrg);
                db.SaveChanges();
                return(GetOrganizationById(newOrg.OrganizationId));
            }
        }
Пример #2
0
        public Event AddNewEvent(CreateEventInfo eventInfo, string UserName)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
            }
            var newEvent = CreateEmptyEvent();

            newEvent.CreatorID  = GetOrganizationById(CurrenUser).OrganizationId;
            newEvent.EventType  = eventInfo.EventType;
            newEvent.EventName  = eventInfo.EventName;
            newEvent.EEventName = ConvertToUnSign.Convert(newEvent.EventName);
            if (eventInfo.StartDate != "")
            {
                newEvent.Start_Date = DateTime.Parse(eventInfo.StartDate);
            }
            if (eventInfo.FinishDate != "")
            {
                newEvent.Finish_Date = DateTime.Parse(eventInfo.FinishDate);
            }
            newEvent.ShortDescription = eventInfo.ShortDescription;
            newEvent.Location         = eventInfo.Location;
            newEvent.ExpectedMoney    = eventInfo.ExpectedMoney;
            newEvent.Description      = eventInfo.Content;
            newEvent.Contact          = eventInfo.Contact;
            newEvent.VideoUrl         = eventInfo.VideoUrl;
            using (var db = new Ws_DataContext())
            {
                db.Events.Add(newEvent);
                db.SaveChanges();
                return(GetEventById(newEvent.EventID));
            }
        }
Пример #3
0
 public bool UpdateUserInfo(UserBasicInfoDTO UserInfo, string userName)
 {
     try
     {
         using (var db = new Ws_DataContext())
         {
             var newInformation = db.User_Information.Where(x => x.Ws_User.UserName == userName).SingleOrDefault();
             if (UserInfo.FullName != null)
             {
                 newInformation.FullName  = UserInfo.FullName;
                 newInformation.EFullName = ConvertToUnSign.Convert(UserInfo.FullName);
             }
             if (UserInfo.Phone != null)
             {
                 newInformation.Phone = UserInfo.Phone;
             }
             if (UserInfo.Address != null)
             {
                 newInformation.UserAddress  = UserInfo.Address;
                 newInformation.EUserAddress = ConvertToUnSign.Convert(UserInfo.Address);
             }
             if (UserInfo.Country != null)
             {
                 newInformation.Country = UserInfo.Country;
             }
             if (UserInfo.Gender != null)
             {
                 newInformation.Gender = UserInfo.Gender;
             }
             if (UserInfo.DOB != "")
             {
                 newInformation.DoB = Convert.ToDateTime(UserInfo.DOB);
             }
             if (UserInfo.FacebookUri != null)
             {
                 newInformation.FacebookUrl = UserInfo.FacebookUri;
             }
             if (UserInfo.UserSignature != null)
             {
                 newInformation.UserSignature = UserInfo.UserSignature;
             }
             db.User_Information.AddOrUpdate(newInformation);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #4
0
        public Thread AddNewThread(CreateThreadInfo thread, string UserName)
        {
            int CurrenUser = 0;

            using (var db = new UserDAL())
            {
                CurrenUser = db.GetUserByUserNameOrEmail(UserName).UserID;
            }
            var newThread = CreateEmptyThread();

            newThread.UserId           = CurrenUser;
            newThread.Title            = thread.Title;
            newThread.Etitle           = ConvertToUnSign.Convert(thread.Title);
            newThread.Content          = thread.Content;
            newThread.ShortDescription = thread.ShortDescription;
            using (var db = new Ws_DataContext())
            {
                db.Threads.Add(newThread);
                db.SaveChanges();
                return(GetThreadById(newThread.ThreadId));
            }
        }
Пример #5
0
        public Ws_User RegisterFacebook(dynamic me)
        {
            string email = me.email;
            // Create new User
            var newUser = new Ws_User
            {
                Email            = email,
                CreatedDate      = DateTime.UtcNow,
                IsActive         = true,
                UserPassword     = string.Empty,
                IsVerify         = true,
                LastLogin        = DateTime.UtcNow,
                AccountType      = false,
                UserName         = "******" + email.Split(new string[] { "@" }, StringSplitOptions.None)[0],
                VerifyCode       = string.Empty,
                User_Information = new User_Information
                {
                    UserAddress         = me.location,
                    FullName            = me.name,
                    EFullName           = ConvertToUnSign.Convert(me.name),
                    Gender              = me.gender,
                    DoB                 = (Convert.ToDateTime(me.birthday) != DateTime.MinValue)?Convert.ToDateTime(me.birthday):null,
                    FacebookUrl         = me.link,
                    ProfileImage        = "https://graph.facebook.com/" + me.id + "/picture?type=large",
                    Country             = string.Empty,
                    Phone               = string.Empty,
                    OrgnazationIDFollow = string.Empty,
                    UserSignature       = string.Empty,
                    Point               = 0
                }
            };

            // Facebook account

            // insert user to Database
            newUser = AddNewUser(newUser);

            return(newUser);
        }
Пример #6
0
        public ActionResult Register(UserRegisterDTO account)
        {
            try
            {
                //Save data to database
                Random rnd        = new Random();
                var    verifycode = rnd.Next(000001, 999999).ToString();
                var    Md5pass    = MD5Helper.MD5Encrypt(account.PassWord);
                var    newUser    = new Ws_User
                {
                    Email            = account.Email,
                    UserName         = account.UserName,
                    UserPassword     = Md5pass,
                    CreatedDate      = DateTime.UtcNow,
                    IsActive         = true,
                    IsVerify         = false,
                    AccountType      = false,
                    VerifyCode       = verifycode,
                    User_Information = new User_Information
                    {
                        ProfileImage = "Content/Images/avatar_default.png",
                        FullName     = account.FullName,
                        EFullName    = ConvertToUnSign.Convert(account.FullName)
                    }
                };
                using (var userDal = new UserDAL())
                {
                    userDal.AddNewUser(newUser);
                }

                // Send Verify code
                //khai báo biến để gửi mã xác nhận
                var    fromAddress  = new MailAddress(WsConstant.VerifyEmail.AdminEmail, WsConstant.VerifyEmail.WsOrganization);
                var    toAddress    = new MailAddress(account.Email, account.UserName);
                string fromPassword = WsConstant.VerifyEmail.AdminEmailPass;
                string subject      = WsConstant.VerifyEmail.EmailSubject;
                string body         = WsConstant.VerifyEmail.EmailContentFirst + "  Tên đăng nhập : " + account.UserName + "\n  Mã xác nhận : " +
                                      verifycode + WsConstant.VerifyEmail.EmailContentLast;
                //xu li gui mail
                var smtp = new SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                };
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                })
                {
                    smtp.Send(message);
                }
                //chuyển đến trang đăng ký thành công
                return(Redirect("/#/RegisterSuccess"));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex;
                return(Redirect("/#/Error"));
            }
        }