Ejemplo n.º 1
0
        public Res_Account Create(Req_Account item)
        {
            try
            {
                using (CMSEntities _context = new CMSEntities())
                {
                    if (!_context.Accounts.Any(x => (x.Username.Equals(item.Email) && x.IsVerifyEmail == true) || (x.PhoneNumber.Equals(item.PhoneNumber) && x.IsVerifyPhone == true)))
                    {
                        var acc = new Account();
                        acc.Active        = item.Active;
                        acc.Address       = item.Address;
                        acc.DateCreated   = DateTime.UtcNow;
                        acc.DateOfBirth   = item.DateOfBirth;
                        acc.Email         = item.Email;
                        acc.PhoneNumber   = item.PhoneNumber;
                        acc.FirstName     = item.FirstName;
                        acc.LastName      = item.LastName;
                        acc.FullName      = item.FirstName + " " + item.LastName;
                        acc.GroupID       = item.GroupID;
                        acc.GUID          = CMS_Helpers.GenerateGUID();
                        acc.IdCardNumber  = item.IdCardNumber;
                        acc.IsVerifyEmail = item.IsVerifyEmail;
                        acc.IsVerifyPhone = item.IsVerifyPhone;
                        acc.Username      = item.Username;
                        acc.Password      = CMS_Helpers.MD5(item.Password);
                        acc.TokenLogin    = CMS_Helpers.GenerateGUID();
                        _context.Accounts.Add(acc);
                        _context.SaveChanges();

                        return(_context.Accounts.Where(x => x.GUID.Equals(acc.GUID)).Select(y => new Res_Account
                        {
                            GUID = y.GUID,
                            FirstName = y.FirstName,
                            LastName = y.LastName,
                            FullName = y.FullName,
                            Username = y.Username,
                            Email = y.Email,
                            PhoneNumber = y.PhoneNumber,
                            Address = y.Address,
                            DateOfBirth = (DateTime)y.DateOfBirth,
                            TokenLogin = y.TokenLogin,
                            Active = (Boolean)y.Active
                        }).SingleOrDefault());
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public Res_Account Update(string GUID, Req_Account item)
        {
            try
            {
                using (CMSEntities _context = new CMSEntities())
                {
                    if (_context.Accounts.Any(x => x.GUID.Equals(GUID)))
                    {
                        var acc = _context.Accounts.SingleOrDefault(x => x.GUID.Equals(GUID));
                        acc.Active       = item.Active;
                        acc.Address      = item.Address;
                        acc.DateOfBirth  = item.DateOfBirth;
                        acc.Email        = item.Email;
                        acc.PhoneNumber  = item.PhoneNumber;
                        acc.FirstName    = item.FirstName;
                        acc.LastName     = item.LastName;
                        acc.FullName     = item.FirstName + " " + item.LastName;
                        acc.GroupID      = item.GroupID;
                        acc.IdCardNumber = item.IdCardNumber;
                        _context.SaveChanges();

                        return(_context.Accounts.Where(x => x.GUID.Equals(GUID)).Select(y => new Res_Account
                        {
                            GUID = y.GUID,
                            FirstName = y.FirstName,
                            LastName = y.LastName,
                            FullName = y.FullName,
                            Username = y.Username,
                            Email = y.Email,
                            PhoneNumber = y.PhoneNumber,
                            Address = y.Address,
                            DateOfBirth = (DateTime)y.DateOfBirth,
                            TokenLogin = y.TokenLogin,
                            Active = (Boolean)y.Active
                        }).SingleOrDefault());
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }