Ejemplo n.º 1
0
        public async Task <Object> UpdatePofile(UpdateRestaurentRequestModel updateRestaurentRequest)
        {
            UpdateResponse responseModel = new UpdateResponse();

            RestaurentRequestModel restautentRequest = await _context.RestaurentRequest.FindAsync(updateRestaurentRequest.ID);

            if (restautentRequest == null)
            {
                return(NotFound());
            }



            restautentRequest.IsVerified = updateRestaurentRequest.IsVerified;
            restautentRequest.Comment    = updateRestaurentRequest.Comment;

            _context.Entry(restautentRequest).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                responseModel.IsSuccess = true;
            }
            catch (Exception)
            {
                responseModel.IsSuccess = false;
                return(responseModel);
            }

            responseModel.UpdatedObject = restautentRequest;



            return(responseModel);
        }
Ejemplo n.º 2
0
        public async Task <Object> RestaurentRegistration(RestaurantRegistrationModel model)
        {
            var usr = await _userManager.FindByEmailAsync(model.OwnerEmail);

            if (usr != null)
            {
                return(BadRequest(new { message = "User Already Exists" }));
            }

            var Role            = "RestaurantOwner";
            var applicationUser = new ApplicationUserModel()
            {
                UserName = model.OwnerEmail,
                Email    = model.OwnerEmail
            };

            ProfileModel profile = new ProfileModel()
            {
                Email       = model.OwnerEmail,
                Name        = model.OwnerName,
                PhoneNumber = model.OwnerPhoneNumber
            };

            RestaurentModel restaurent = new RestaurentModel()
            {
                OwnerEmail      = model.OwnerEmail,
                RestaurantEmail = model.RestaurantEmail,
                Phone           = model.RestaurantPhone,
                Name            = model.RestaurantName,
                Location        = model.ResturantAddress
            };

            try
            {
                var result = await _userManager.CreateAsync(applicationUser, model.Password);

                await _userManager.AddToRoleAsync(applicationUser, Role);

                _context.Profile.Add(profile);
                _context.Restaurent.Add(restaurent);
                await _context.SaveChangesAsync();

                var resturantID = _context.Restaurent.Where(r => r.OwnerEmail == model.OwnerEmail).FirstOrDefault().ID;

                RestaurentRequestModel restaurentRequest = new RestaurentRequestModel()
                {
                    IsVerified           = false,
                    RegistrationDateTime = DateTime.Now,
                    RestaurentID         = resturantID
                };

                _context.RestaurentRequest.Add(restaurentRequest);
                await _context.SaveChangesAsync();

                if (result.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(applicationUser);

                    var callbackUrl = Url.Action(("ConfirmEmail"), "User", new { userId = applicationUser.Id, code = code }, Request.Scheme);

                    EmailSender emailSender = new EmailSender();
                    emailSender.sendVerificationEmail(model.OwnerEmail, callbackUrl);
                }
                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }