Beispiel #1
0
        public IHttpActionResult CreateCustomer(BuyingProductDto buyingProductDto)
        {
            IdentityUser user = db.Users.Where(a => a.UserName == ControllerContext.RequestContext.Principal.Identity.Name).FirstOrDefault();

            if (user == null)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content    = new StringContent("User doesn't exist."),
                    StatusCode = HttpStatusCode.NotFound
                };
                throw new HttpResponseException(response);
            }

            if (buyingProductDto == null)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content    = new StringContent("buyingProductDto parameter doesn't exist."),
                    StatusCode = HttpStatusCode.NotFound
                };
                throw new HttpResponseException(response);
            }

            var p = db.Products.Where(a => a.Code == buyingProductDto.Code).FirstOrDefault();

            if (p == null)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content    = new StringContent("product code doesn't exist."),
                    StatusCode = HttpStatusCode.NotFound
                };
                throw new HttpResponseException(response);
            }

            BuyingProduct buyingProduct = new BuyingProduct()
            {
                NumberBuying    = buyingProductDto.NumberBuying,
                AmountBuying    = buyingProductDto.AmountBuying,
                ProductId       = p.Id,
                UnitPriceBuying = buyingProductDto.UnitPriceBuying,
                IsLoading       = false,
                UserId          = user.Id,
                CreationTime    = DateTime.Now
            };

            db.BuyingProducts.Add(buyingProduct);
            db.SaveChanges();

            return(Ok("buyingProduct was created succesfully"));
        }
Beispiel #2
0
        public async Task <IActionResult> Select(Guid item, string button)
        {
            if (button == "delete")
            {
                var h = _db.Products.Get(item);
                _db.Products.Delete(h.Id);
                _db.Save();
                return(View("ProductList", _db.Products.GetAllList().ToList()));
            }
            if (button == "change")
            {
                return(View("Shift", item));
            }
            if (button == "buy")
            {
                //  User user = await _userManager.FindByIdAsync(Convert.ToString(item));
                // if ((await _userManager.IsInRoleAsync(user, "Client") == true) && (user!=null))
                if (User.IsInRole("Client"))
                {
                    var user = await _userManager.FindByNameAsync(User.Identity.Name);

                    var h = _db.Clients.Get(Guid.Parse(user.Id));
                    if (h == null)
                    {
                        Client client = new Client
                        {
                            Name = User.Identity.Name,
                            Code = GenerateCodeClient.Generate(),
                            Id   = Guid.Parse(user.Id)
                        };
                        _db.Clients.Create(client);
                        _db.Save();

                        BuyingProduct.AddToCan(_db, client, _db.Products.Get(item));

                        return(View("Buy", _db));
                    }
                    else
                    {
                        BuyingProduct.AddToCan(_db, h, _db.Products.Get(item));

                        return(View("Buy", _db));
                    }
                }
                return(RedirectToAction("Index", "Home"));
            }
            return(View("ProductList", _db.Products.GetAllList().ToList()));
        }
Beispiel #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            BuyingProduct buyingProduct = new BuyingProduct();

            buyingProduct.ShowDialog();
        }