コード例 #1
0
        public async Task <IActionResult> Put(int id)
        {
            string email = User.FindFirst(ClaimTypes.NameIdentifier).Value;

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

            ShoppingList shoppingList = await _context.ShoppingList.FindAsync(id);

            Person deliverer = _context.Person.FirstOrDefault(person => person.Email == email);

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

            shoppingList.Deliverer = deliverer.PersonId;

            _context.Attach(shoppingList);
            _context.Entry(shoppingList).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromForm] ShopDTOin shop)
        {
            var stream = shop.Picture.OpenReadStream();

            CloudinaryDotNet.Account account = new CloudinaryDotNet.Account("drtn3myw4", "662324151252959", "nX0XPARZfpO_WRuESu_3cPoidrA");

            CloudinaryDotNet.Cloudinary cloudinary = new CloudinaryDotNet.Cloudinary(account);

            CloudinaryDotNet.Actions.ImageUploadParams uploadParams = new CloudinaryDotNet.Actions.ImageUploadParams()
            {
                File = new CloudinaryDotNet.FileDescription(shop.Picture.Name, stream)
            };

            CloudinaryDotNet.Actions.ImageUploadResult uploadResult = cloudinary.Upload(uploadParams);

            Shop newShop = new Shop();

            newShop.Name        = shop.Name;
            newShop.Address     = shop.Address;
            newShop.PicturePath = uploadResult.SecureUri.ToString();
            newShop.Locality    = shop.Locality;
            newShop.Description = shop.Description;
            _context.Shop.Add(newShop);
            await _context.SaveChangesAsync();

            return(Created($"api/Shop/{newShop.ShopId}", newShop));
        }
コード例 #3
0
        public async Task <ActionResult <Person> > Post([FromBody] Person person)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Boolean emailExist = await _context.Person.AnyAsync(per => per.Email == person.Email);

            if (emailExist)
            {
                // TODO
            }

            Boolean localityExist = await _context.Locality.AnyAsync(loc => loc.LocalityId == person.Locality);

            if (!localityExist)
            {
                // TODO
            }

            using (SHA256 sha256Hash = SHA256.Create())
            {
                byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(person.Password));


                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < bytes.Length; i++)
                {
                    builder.Append(bytes[i].ToString("x2"));
                }
                person.Password = builder.ToString();
            }

            _context.Person.Add(person);
            await _context.SaveChangesAsync();

            return(Created($"api/Person/{person.PersonId}", person));
        }
コード例 #4
0
        public async Task <IActionResult> Post(int shopId)
        {
            string email       = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            Person personFound = _context.Person.FirstOrDefault(person => person.Email == email);

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

            var person = from i in _context.Person
                         where i.Email == email
                         select new Person();

            Shop shop = _context.Shop.Find(shopId);

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

            Favorite favorite = new Favorite();

            favorite.Person = personFound.PersonId;
            favorite.Shop   = shopId;

            Favorite heart = _context.Favorite.Where(x => x.Person == personFound.PersonId && x.Shop == shop.ShopId).FirstOrDefault();

            if (heart != null)
            {
                _context.Favorite.Remove(heart);
            }

            else
            {
                _context.Favorite.Add(favorite);
            }

            await _context.SaveChangesAsync();

            return(NoContent());
        }