public ActionResult Create([Bind(Include = "ShopAssistantName")] ShopAssistantDTO shopAssistantDTO)
        {
            IUnitOfWork database = new EFUnitOfWork();

            var shopAssistant = new ShopAssistantDAL {
                ShopAssistantName = shopAssistantDTO.ShopAssistantName, Id = shopAssistantDTO.Id
            };

            try
            {
                if (ModelState.IsValid)
                {
                    database.ShopAssistants.Insert(shopAssistant);
                    database.ShopAssistants.Save();
                    return(RedirectToAction("Index"));
                }
            }

            catch (DataException /* dex */)
            {
                //Log the error (uncomment dex variable name after DataException and add a line here to write a log.
                ModelState.AddModelError(string.Empty, "Unable to save changes. Try again, and if the problem persists contact your system administrator.");
            }

            return(View(shopAssistantDTO));
        }
Beispiel #2
0
        public void AddOrder(OrderDTO orderDTO)
        {
            lock (_locker)
            {
                var ShopAssistant = new ShopAssistantDAL()
                {
                    ShopAssistantName = orderDTO.ShopAssistant
                };
                var customer = new CustomerDAL()
                {
                    CustomerName = orderDTO.Customer
                };
                var product = new ProductDAL()
                {
                    ProductName = orderDTO.Product,
                    //    if (orderDto.Amount == 0)
                    //{
                    //    throw new DivideByZeroException();
                    //}
                    ProductPrice = orderDTO.Price / orderDTO.Amount
                };

                var ShopAssistantId = database.ShopAssistants.GetId(ShopAssistant);
                if (ShopAssistantId == null)
                {
                    database.ShopAssistants.Insert(ShopAssistant);
                    database.Save();
                    ShopAssistantId = database.ShopAssistants.GetId(ShopAssistant);
                }

                var CustomerId = database.Customers.GetId(customer);
                if (CustomerId == null)
                {
                    database.Customers.Insert(customer);
                    database.Save();
                    CustomerId = database.Customers.GetId(customer);
                }

                var productId = database.Products.GetId(product);
                if (productId == null)
                {
                    database.Products.Insert(product);
                    database.Save();
                    productId = database.Products.GetId(product);
                }

                OrderDAL order = new OrderDAL
                {
                    OrderDate       = orderDTO.OrderDate,
                    ShopAssistantId = ShopAssistant.Id,
                    CustomerId      = customer.Id,
                    ProductId       = product.Id,
                    Price           = orderDTO.Price,
                    Amount          = orderDTO.Amount
                };
                database.Orders.Insert(order);
                database.Save();
            }
        }
Beispiel #3
0
        public void AddOrder(OrderDTO orderDTO)
        {
            lock (_locker)
            {
                var ShopAssistant = new ShopAssistantDAL()
                {
                    ShopAssistantName = orderDTO.ShopAssistant
                };
                var customer = new CustomerDAL()
                {
                    CustomerName = orderDTO.Customer
                };
                //var orderDate = new OrderDAL() { OrderDate = orderDTO.OrderDate };
                var product = new ProductDAL()
                {
                    ProductName = orderDTO.Product,
                    //        if (orderDto.Amount == 0)
                    //{
                    //    throw new DivideByZeroException();
                    //}
                    ProductPrice = orderDTO.Price / orderDTO.Amount
                };

                var ShopAssistantId = database.ShopAssistants.GetId(ShopAssistant);
                if (ShopAssistantId == null)
                {
                    database.ShopAssistants.Insert(ShopAssistant);
                    database.Save();
                    ShopAssistantId = database.ShopAssistants.GetId(ShopAssistant);
                }

                var CustomerId = database.Customers.GetId(customer);
                if (CustomerId == null)
                {
                    database.Customers.Insert(customer);
                    database.Save();
                    CustomerId = database.Customers.GetId(customer);
                }

                var productId = database.Products.GetId(product);
                if (productId == null)
                {
                    database.Products.Insert(product);
                    database.Save();
                    productId = database.Products.GetId(product);
                }

                if (orderDTO.OrderDate.Year == 1)
                {
                    orderDTO.OrderDate = DateTime.Now;
                }

                if (orderDTO.Id == 0)
                {
                    var last = database.Orders.GetAll().Last();
                    orderDTO.Id = last.Id + 1;
                }

                OrderDAL order = new OrderDAL
                {
                    Id              = orderDTO.Id,
                    OrderDate       = orderDTO.OrderDate,
                    ShopAssistantId = ShopAssistantId.Value,
                    CustomerId      = CustomerId.Value,
                    ProductId       = productId.Value,
                    Price           = orderDTO.Price,
                    Amount          = orderDTO.Amount
                };

                database.Orders.Insert(order);
                database.Save();
            }
        }