Пример #1
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);
        }