Esempio n. 1
0
        public ProductDTO AddProduct(ProductDTO productDTO)
        {
            if (productDTO == null)
            {
                return(new ProductDTO());
            }

            var newProduct = ToProduct(productDTO);

            using (var context = new MyEntity())
            {
                try
                {
                    var currentProduct = context.Products.SingleOrDefault(o => o.ProductGUID == productDTO.ProductGUID);

                    if (currentProduct == null && productDTO != null && !string.IsNullOrWhiteSpace(productDTO.ProductName))
                    {
                        newProduct.ProductGUID          = Guid.NewGuid();
                        context.Entry(newProduct).State = EntityState.Added;
                        context.SaveChanges();
                    }
                    else
                    {
                        return(new ProductDTO());
                    }
                }
                catch (SqlException ex)
                {
                    // Log exception here
                    return(new ProductDTO());
                }
            }

            return(ToProductDTO(newProduct));
        }
Esempio n. 2
0
        public bool UpdateProduct(ProductDTO productDTO)
        {
            if (productDTO == null || productDTO.ProductGUID == Guid.Empty)
            {
                return(false);
            }

            using (var context = new MyEntity())
            {
                try
                {
                    var currentProduct = context.Products.SingleOrDefault(o => o.ProductGUID == productDTO.ProductGUID);

                    if (currentProduct == null)
                    {
                        // Log 'Product Not Found' here
                        return(false);
                    }

                    currentProduct.ProductName = productDTO.ProductName;
                    currentProduct.Quantity    = productDTO.Quantity;

                    context.Entry(currentProduct).State = EntityState.Modified;
                    context.SaveChanges();
                }
                catch (SqlException ex)
                {
                    // Log 'SqlException' here
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
        public bool DeleteProduct(Guid productGUID)
        {
            using (var context = new MyEntity())
            {
                try
                {
                    var product = context.Products.SingleOrDefault(o => o.ProductGUID == productGUID);

                    if (product != null)
                    {
                        context.Entry(product).State = EntityState.Deleted;

                        context.SaveChanges();
                    }
                }
                catch (SqlException ex)
                {
                    // Log exception here
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 4
0
        // Update Data

        public void updatePaymentAndCommisionById(int id, PaymentDtl paymentDtl)
        {
            try
            {
                PaymentDtl user = db.PaymentDtls.Find(id);
                user.commision   = paymentDtl.commision;
                user.trainerFees = paymentDtl.trainerFees;
                db.Configuration.ValidateOnSaveEnabled = false;
                db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                db.Configuration.ValidateOnSaveEnabled = true;
                db.SaveChanges();
            }
            catch
            {
                throw;
            }
        }