Пример #1
0
        public void LoadImage(string email, string path)
        {
            User user = context.Users.Where(x => x.Email == email).FirstOrDefault();

            user.ProfilePhoto = path;
            context.Users.Update(user);
            context.SaveChanges();
        }
        public IActionResult InsertNewNotification(Guid userId, [FromBody] NewProductRequest incomingProduct) // [FromBody] tag is a must to clarify
        {
            var productId = Guid.NewGuid();

            if (incomingProduct.newProduct)
            {
                if (_context.Products.Where(x => x.ProductName == incomingProduct.ProductName && x.UserId == userId).FirstOrDefault() == null)
                {
                    var newProduct = new Product();
                    newProduct.ProductId   = productId;
                    newProduct.Barcode     = incomingProduct.Barcode;
                    newProduct.Category    = incomingProduct.Category;
                    newProduct.ProductName = incomingProduct.ProductName;
                    newProduct.UserId      = userId;

                    _context.Products.Add(newProduct);
                }
                else
                {
                    productId = _context.Products.Where(x => x.ProductName == incomingProduct.ProductName).First().ProductId;
                }
            }
            else if (incomingProduct.productId != null)
            {
                productId = incomingProduct.productId.Value;

                Product product = _context.Products.FirstOrDefault(x => x.ProductId == productId && x.UserId == userId);
                if (incomingProduct.ProductName != "" && incomingProduct.ProductName != product.ProductName)
                {
                    product.ProductName = incomingProduct.ProductName;
                }
                if (incomingProduct.Category != "" && incomingProduct.Category != product.Category)
                {
                    product.Category = incomingProduct.Category;
                }

                _context.Products.Update(product);
            }
            else
            {
                productId = _context.Products.Where(x => x.ProductName == incomingProduct.ProductName).First().ProductId;
            }

            Notification notifcation = new Notification();

            notifcation.NotificationId = new Guid();
            notifcation.ProductId      = productId;
            notifcation.UserId         = userId;
            notifcation.EntryDate      = DateTime.Now;
            notifcation.ExpiryDate     = DateTime.Now.AddDays(incomingProduct.ReservedDays);
            notifcation.IsEaten        = false;
            notifcation.Note           = incomingProduct.Note;
            _context.Notifications.Add(notifcation);
            _context.SaveChanges();

            return(Ok());
        }
Пример #3
0
        public bool Post(PostDto postdto)
        {
            Post post = new Post();

            post.Text        = postdto.Text;
            post.UserId      = postdto.UserId;
            post.LikeCount   = 0;
            post.IsDeleted   = false;
            post.Image       = postdto.Image;
            post.LikeCount   = 0;
            post.CreatedDate = DateTime.Now;
            context.Posts.Add(post);
            var result = context.SaveChanges();

            if (result > default(int))
            {
                return(true);
            }
            return(false);
        }
Пример #4
0
        public IActionResult UpdateProductCategoryById(Guid userId, Guid productId, [FromBody] UpdateProductRequest incomingInfo)
        {
            Product product = _context.Products.FirstOrDefault(x => x.ProductId == productId && x.UserId == userId);

            if (incomingInfo.ProductName != "")
            {
                product.ProductName = incomingInfo.ProductName;
            }
            if (incomingInfo.Category != "")
            {
                product.Category = incomingInfo.Category;
            }

            _context.Products.Update(product);
            _context.SaveChanges();

            return(Ok());
        }
Пример #5
0
        /// <summary>
        /// Insere uma lista de pessoas com transação ReadCommited
        /// </summary>
        /// <param name="pessoas"></param>
        public int InserePessoas(List <Pessoa> pessoas)
        {
            try
            {
                using (var transaction = fb.Database.BeginTransaction())
                {
                    fb.Pessoa.AddRange(pessoas);
                    int ret = fb.SaveChanges();

                    transaction.Commit();

                    return(ret);
                }
            }
            catch (Exception E)
            {
                throw new Exception("GetPessoas", E);
            }
        }
Пример #6
0
        public IActionResult CreateUser([FromBody] RegisterRequest userInfo)
        {
            var UserId = Guid.NewGuid();

            if (userInfo.Password == userInfo.PasswordRepeat)
            {
                User newUser = new User();
                newUser.UserId      = UserId;
                newUser.Name        = userInfo.Name;
                newUser.Email       = userInfo.Email;
                newUser.PhoneNumber = userInfo.PhoneNumber;

                //Hash password
                var md5 = new MD5CryptoServiceProvider();

                ///first we convert the text to bytes first
                var bytePassword = Encoding.ASCII.GetBytes(userInfo.Password);

                //this is the hash password
                var newHashPassword = md5.ComputeHash(bytePassword);


                //apparently we need to do this to convert to a properly string

                // save
                newUser.Password = HashString(newHashPassword);

                _context.Users.Add(newUser);
                _context.SaveChanges();
            }
            else
            {
                return(StatusCode(400)); //bad request
            }
            // fetch back the created user info
            var user     = _context.Users.First(x => x.UserId == UserId);
            var response = new UserResponse();

            response.UserId = user.UserId;
            response.Name   = user.Name;
            return(Ok(response));
        }
        public bool AddMessage(int OwnerId, int SentTo, string message, string photo)
        {
            Message msg = new Message();

            msg.CreatedDate = DateTime.Now;
            msg.OwnerUserId = OwnerId;
            msg.SentTo      = SentTo;
            msg.Text        = message;
            msg.UserPhoto   = photo;

            _context.Messages.Add(msg);

            int result = _context.SaveChanges();

            if (result > 0)
            {
                return(true);
            }

            return(false);
        }