Beispiel #1
0
        public async Task <int> Post(AdminAccount model)
        {
            string user      = _appSetting.GetValue <string>("AppSettings:EmailAuthentication:UserName");
            string password  = _appSetting.GetValue <string>("AppSettings:EmailAuthentication:Password");
            string activeUrl = _appSetting.GetValue <string>("AppSettings:ActiveUrl");

            //restaurant owner create account
            if (_authenticationDto.RestaurantId > 0)
            {
                model.RestaurantId = _authenticationDto.RestaurantId;
            }
            var result = 0;

            if (ModelState.IsValid)
            {
                var dateTimeUtcNow = DateTime.Now;
                model.PasswordHash   = WebsiteExtension.EncryptPassword(model.PasswordHash);
                model.CreatedStaffId = _authenticationDto.UserId;
                model.CreatedDate    = dateTimeUtcNow;
                model.Status         = 1;
                model.Active         = 0;
                //recheck eamil and username is existed
                if (!await _adminAccountBusiness.CheckEmailExist(model.Email) ||
                    !await _adminAccountBusiness.CheckUserNameExist(model.UserName))
                {
                    return(result);
                }
                var modelInsert = await _adminAccountBusiness.Add(model);

                result = modelInsert.Id;
                if (result > 0)
                {
                    await _emailBusiness.SendEmailToActiveAccount(modelInsert, user, password, activeUrl);
                }
            }
            return(result);
        }
Beispiel #2
0
        public async Task <int> Post(Entities.Models.Restaurant model)
        {
            string user      = _appSetting.GetValue <string>("AppSettings:EmailAuthentication:UserName");
            string password  = _appSetting.GetValue <string>("AppSettings:EmailAuthentication:Password");
            string activeUrl = _appSetting.GetValue <string>("AppSettings:ActiveUrl");
            var    result    = 0;

            if (ModelState.IsValid)
            {
                model.Status = 1;
                var modelInsert = await _restaurantBusiness.Add(model);

                result = modelInsert.Id;
                if (result > 0)
                {
                    var dateTimeUtcNow = DateTime.Now;
                    var accountModel   = new AdminAccount
                    {
                        UserName       = WebsiteExtension.Slug(modelInsert.Name),
                        RestaurantId   = modelInsert.Id,
                        Email          = modelInsert.Email,
                        PasswordHash   = WebsiteExtension.EncryptPassword(WebsiteExtension.Slug(modelInsert.Name) + "123"),
                        CreatedStaffId = _authenticationDto.UserId,
                        CreatedDate    = dateTimeUtcNow,
                        Status         = 1,
                        Active         = 0
                    };
                    var accountInsert = await _adminAccountBusiness.Add(accountModel);

                    if (accountInsert.Id > 0)
                    {
                        await _emailBusiness.SendEmailToRestaurantAdmin(accountInsert, user, password, activeUrl);
                    }
                }
            }
            return(result);
        }