Ejemplo n.º 1
0
        private async Task <RestaurantOwner> LoginUser(LoginCustomer loginCustomer)
        {
            RestaurantOwner restaurantOwner = _context.RestaurantOwners.Include(r => r.Restaurant).FirstOrDefault(r => r.email == loginCustomer.Username);

            if (restaurantOwner.password == loginCustomer.Password)
            {
                return(restaurantOwner);
            }
            return(null);
            //   var client = _httpClientFactory.CreateClient();
            //   client.BaseAddress = new Uri("http://127.0.0.1:8000");
            //   client.DefaultRequestHeaders.Accept.Clear();
            //   client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            //   var formContent = new FormUrlEncodedContent(new[]
            //{

            //    new KeyValuePair<string, string>("email", loginCustomer.Username),
            //    new KeyValuePair<string, string>("password", loginCustomer.Password),
            //});

            //   using var httpResponse =
            //       await client.PostAsync("/rest-auth/login/", formContent);

            //   if (httpResponse.IsSuccessStatusCode)
            //   {

            //       return true;
            //   }
            //   else
            //   {
            //       return false;
            //   }
        }
        public IHttpActionResult PutRestaurantOwner(int id, RestaurantOwner restaurantOwner)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != restaurantOwner.Id)
            {
                return(BadRequest());
            }

            db.Entry(restaurantOwner).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantOwnerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public static void InsertRestaurantOwner(RestaurantOwner ro)
        {
            using (RestaurantContext db = new RestaurantContext())
            {
                if (ro == null)
                {
                    return;
                }
                if (db.RestaurantOwners.ToList().Count == 0)
                {
                    db.RestaurantOwners.Add(ro);
                    db.SaveChanges();
                    return;
                }
                int rmId;
                foreach (var item in db.RestaurantOwners.Include("Restaurant.Grade").Include("Restaurant.Food.Grade").Include("Restaurant.Wine.Grade"))
                {
                    if (item.Username.Equals(ro.Username))
                    {
                        rmId = item.Restaurant.id;
                        db.RestaurantOwners.Remove(item);
                    }
                }
                db.RestaurantOwners.Add(ro);

                db.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            RestaurantOwner restaurantOwner = db.RestaurantOwners.Find(id);

            db.RestaurantOwners.Remove(restaurantOwner);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "OwnerId,OwnerName,UserId")] RestaurantOwner restaurantOwner)
 {
     if (ModelState.IsValid)
     {
         db.Entry(restaurantOwner).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(restaurantOwner));
 }
        public IHttpActionResult GetRestaurantOwner(string userName, string password)
        {
            RestaurantOwner restaurantOwner = db.RestaurantOwners.Where(x => x.UserName == userName && x.Password == password).FirstOrDefault();

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

            return(Ok(restaurantOwner));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Login(LoginCustomer loginCustomer)
        {
            RestaurantOwner restaurantOwner = await LoginUser(loginCustomer);

            if (restaurantOwner != null)
            {
                // MyapiCustomer customer = _context.MyapiCustomers.FirstOrDefault(c => c.Email == loginCustomer.Username);
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, restaurantOwner.Restaurant.Name),
                    new Claim(ClaimTypes.NameIdentifier, restaurantOwner.Restaurant.Id.ToString()),
                    new Claim("FullName", restaurantOwner.email)
                };

                var claimsIdentity = new ClaimsIdentity(
                    claims, CookieAuthenticationDefaults.AuthenticationScheme);

                var authProperties = new AuthenticationProperties
                {
                    AllowRefresh = true,
                    // Refreshing the authentication session should be allowed.

                    ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(60),
                    // The time at which the authentication ticket expires. A
                    // value set here overrides the ExpireTimeSpan option of
                    // CookieAuthenticationOptions set with AddCookie.

                    IsPersistent = true,
                    // Whether the authentication session is persisted across
                    // multiple requests. When used with cookies, controls
                    // whether the cookie's lifetime is absolute (matching the
                    // lifetime of the authentication ticket) or session-based.

                    //IssuedUtc = <DateTimeOffset>,
                    // The time at which the authentication ticket was issued.

                    //RedirectUri = <string>
                    // The full path or absolute URI to be used as an http
                    // redirect response value.
                };

                await HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    new ClaimsPrincipal(claimsIdentity),
                    authProperties);

                return(RedirectToAction("Index", "Orders"));
            }
            return(View());
        }
Ejemplo n.º 8
0
        // GET: RestaurantOwners/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RestaurantOwner restaurantOwner = db.RestaurantOwners.Find(id);

            if (restaurantOwner == null)
            {
                return(HttpNotFound());
            }
            return(View(restaurantOwner));
        }
        public IHttpActionResult DeleteRestaurantOwner(int id)
        {
            RestaurantOwner restaurantOwner = db.RestaurantOwners.Find(id);

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

            db.RestaurantOwners.Remove(restaurantOwner);
            db.SaveChanges();

            return(Ok(restaurantOwner));
        }
Ejemplo n.º 10
0
        public ActionResult Create([Bind(Include = "OwnerId,OwnerName")] RestaurantOwner restaurantOwner)
        {
            restaurantOwner.UserId = User.Identity.GetUserId();

            ModelState.Clear();
            TryValidateModel(restaurantOwner);

            if (ModelState.IsValid)
            {
                db.RestaurantOwners.Add(restaurantOwner);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(restaurantOwner));
        }
Ejemplo n.º 11
0
 public static RestaurantOwner GetRestaurantOwner(Login loginObject)
 {
     using (RestaurantContext db = new RestaurantContext())
     {
         if (db.RestaurantOwners.ToList().Count == 0)
         {
             return(new RestaurantOwner());
         }
         RestaurantOwner ro = db.RestaurantOwners.Include("Restaurant.Grade").Include("Restaurant.Food.Grade").Include("Restaurant.Wine.Grade").Where(item => item.Username.Equals(loginObject.Username)).FirstOrDefault();
         if (ro.Pass.Equals(loginObject.Password))
         {
             return(ro);
         }
         else
         {
             return(new RestaurantOwner());
         }
     }
 }
        public async Task Create(RestaurantOwnerCreateDto model)
        {
            int quantityUsers = _context.Users.Count();

            var user = new RestaurantOwner
            {
                UserId   = quantityUsers + 1,
                Email    = model.Email,
                UserName = model.Email,
                Name     = model.Name
            };

            var result = await _userManager.CreateAsync(user, model.Password);

            await _userManager.AddToRoleAsync(user, RoleHelper.RESTAURANTOWNER);

            if (!result.Succeeded)
            {
                throw new Exception("No se pudo registrar el usuario.");
            }
        }
Ejemplo n.º 13
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            int Fvid = Program.GetVid <int>(Program.URL_GENERATE_VID_PATH);

            List <Food> hrana = new List <Food>();
            //hrana.Add(new Food("Njoke", new GradeSpread(1, 2, 3, 40, 50), 45.99, "https://images.immediate.co.uk/production/volatile/sites/30/2020/08/chorizo-mozarella-gnocchi-bake-cropped-9ab73a3.jpg?quality=90&resize=700%2C636",0));
            List <Wine> vina = new List <Wine>();
            //vina.Add(new Wine("Riojas", new GradeSpread(1, 2, 3, 49, 150), 450.50, "https://www.chicagotribune.com/resizer/HMeCjL9nZGdSkbNDYr5IPIOSfAA=/1200x675/top/www.trbimg.com/img-5a8d6e51/turbine/ct-1519218254-hmtw3mzmjp-snap-image", 1));
            //Register();
            RestaurantOwner owner = new RestaurantOwner(tbUserName.Text, tbPass.Text,
                                                        new RestaurantModel(tbRestaurantName.Text, tbRestaurantDetails.Text,
                                                                            hrana,
                                                                            vina,
                                                                            new GradeSpread(0, 0, 0, 0, 0), "https://www.klikcup.com/images/objects/2022/mlynec-restaurant-2.jpg",
                                                                            Program.GetVid <int>(Program.URL_GENERATE_VID_PATH)));

            //System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(owner.GetType());
            //x.Serialize(Console.Out, owner);
            Program.BackendConnect <RestaurantOwner>(owner, Program.URL_REGISTRATION_PATH);
            this.Close();
            Program.previousForm.Show();
        }
        public IHttpActionResult PostRestaurantOwner(string name, int restaurantId, string userName, string password)
        {
            var id = db.RestaurantOwners.Max(x => x.Id) + 1;

            var restaurantOwner = new RestaurantOwner
            {
                Id           = id,
                Name         = name,
                Password     = password,
                RestaurantId = restaurantId,
                UserName     = userName
            };

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.RestaurantOwners.Add(restaurantOwner);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = restaurantOwner.Id }, restaurantOwner));
        }
Ejemplo n.º 15
0
 public void PostInsert([FromBody] RestaurantOwner ro)
 {
     DBLogic.InsertRestaurantOwner(ro);
 }