Ejemplo n.º 1
0
        public async Task <ActionResult> Create([Bind(Include = "ProductSalesID,ProductID,SalesID,Quantity,DateCreated,DateModified,ModifiedBy")] ProductSales productSales)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var quantityRequest  = productSales.Quantity;
                    var result           = db.Stock.Where(p => p.ProductID == productSales.ProductID).FirstOrDefault();
                    var quantityRemaning = result.QuantityRemaining;
                    //if remaining qunatity >= requested quantity
                    if (quantityRemaning >= quantityRequest)
                    {
                        if (productSales.DateCreated == null)
                        {
                            productSales.DateCreated = DateTime.Now;
                        }
                        if (productSales.DateModified == null)
                        {
                            productSales.DateModified = DateTime.Now;
                        }
                        productSales.ModifiedBy = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                        db.ProductSales.Add(productSales);
                        db.SaveChanges();

                        using (IMSEntities db = new IMSEntities())
                        {
                            int productId   = productSales.ProductID;
                            var quantity    = productSales.Quantity;
                            var product     = QueryHelper.GetProductPrice(db, productId).FirstOrDefault();
                            var totalAmount = quantity * product.PricePerItem;
                            var bill        = productSales.SalesID;
                            await QueryHelper.UpdateBillingAmount(db, totalAmount, bill);

                            var quantityremaining      = QueryHelper.GetQuantity(db, productId).FirstOrDefault();
                            var totalquantityremaining = quantityremaining.QuantityRemaining - quantity;
                            await QueryHelper.UpdateQuantityRemaining(db, totalquantityremaining, productId);
                        }
                    }

                    else
                    {
                        throw new Exception("Insufficient item in the stock");
                    }
                }
                return(RedirectToAction("Index"));
            }

            catch (Exception e)
            {
                ViewBag.Error = e.Message;
            }

            ViewBag.ProductID  = new SelectList(db.Product, "ProductID", "ProductName", productSales.ProductID);
            ViewBag.ModifiedBy = new SelectList(db.UserAccounts, "UserAccountID", "Email", productSales.ModifiedBy);
            ViewBag.SalesID    = new SelectList(db.Sales, "SalesID", "SalesID", productSales.SalesID);

            return(View(productSales));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "ID,Name,Gender,Email")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Name,CategoryId,Quantity,Price,AddedDate,ModifiedDate,Status")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Ejemplo n.º 4
0
        public Intervention create(Intervention intervention)
        {
            using (IMSEntities context = new IMSEntities())
            {
                Intervention newIntervention = new Intervention(intervention);
                context.Interventions.Add(newIntervention);
                context.SaveChanges();

                return(newIntervention);
                //     Intervention inter=context.Interventions.Add(new Intervention(intervention));
                //try
                //{
                //    context.SaveChanges();
                //}
                //catch (DbEntityValidationException dbEx)
                //{
                //    foreach (var validationErrors in dbEx.EntityValidationErrors)
                //    {
                //        foreach (var validationError in validationErrors.ValidationErrors)
                //        {
                //            Trace.TraceInformation("Property: {0} Error: {1}",
                //                                    validationError.PropertyName,
                //                                    validationError.ErrorMessage);
                //        }
                //    }
                //}
                //return (Intervention)context.Interventions.Find(intervention.Id);
                //  return intervention;
            }
        }
Ejemplo n.º 5
0
 public District create(District district)
 {
     using (IMSEntities context = new IMSEntities())
     {
         context.Districts.Add(new District(district));
         context.SaveChanges();
         return(context.Districts.Find(district));
     }
 }
Ejemplo n.º 6
0
 public InterventionType create(InterventionType interventionType)
 {
     using (IMSEntities context = new IMSEntities())
     {
         context.InterventionTypes.Add(new InterventionType(interventionType));
         context.SaveChanges();
         return(context.InterventionTypes.Find(interventionType));
     }
 }
Ejemplo n.º 7
0
 public User createUser(User user)
 {
     using (IMSEntities context = new IMSEntities())
     {
         context.Users.Add(new User(user));
         context.SaveChanges();
         return(context.Users.Find(user));
     }
 }
Ejemplo n.º 8
0
 public Client createClient(Client client)
 {
     using (IMSEntities context = new IMSEntities())
     {
         Client newClient = new Client(client);
         context.Clients.Add(newClient);
         context.SaveChanges();
         return(newClient);
     }
 }
        public ActionResult Create([Bind(Include = "UserTypeID,UserTypeName,DateCreated,DateModified")] UserType userType)
        {
            if (ModelState.IsValid)
            {
                if (userType.DateCreated == null)
                {
                    userType.DateCreated = DateTime.Now;
                }
                if (userType.DateModified == null)
                {
                    userType.DateModified = DateTime.Now;
                }
                db.UserType.Add(userType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userType));
        }
        public ActionResult Create([Bind(Include = "ProductDetailID,ProductID,UnitCostPrice,Location,ThresholdQuantity,Unit,DateCreated,DateModified")] ProductXDetails productXDetails)
        {
            if (ModelState.IsValid)
            {
                if (productXDetails.DateCreated == null)
                {
                    productXDetails.DateCreated = DateTime.Now;
                }
                if (productXDetails.DateModified == null)
                {
                    productXDetails.DateModified = DateTime.Now;
                }
                db.ProductXDetails.Add(productXDetails);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductID = new SelectList(db.Product, "ProductID", "ProductName", productXDetails.ProductID);
            return(View(productXDetails));
        }
Ejemplo n.º 11
0
        public ActionResult Register([Bind(Include = "UserID,Name,UserName,Email,Password")] UserDetail userDetail)
        {
            if (ModelState.IsValid)
            {
                db.UserDetails.Add(userDetail);
                db.SaveChanges();
                return(RedirectToAction("Login"));
            }

            return(View(userDetail));
        }
Ejemplo n.º 12
0
        public ActionResult Create([Bind(Include = "SupplierID,SupplierEmail,RegistrationNumber,SupplierName,DateCreated,DateModified,ModifiedBy")] Suppliers suppliers)
        {
            if (ModelState.IsValid)
            {
                if (suppliers.DateCreated == null)
                {
                    suppliers.DateCreated = DateTime.Now;
                }
                if (suppliers.DateModified == null)
                {
                    suppliers.DateModified = DateTime.Now;
                }
                suppliers.ModifiedBy = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                db.Suppliers.Add(suppliers);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ModifiedBy = new SelectList(db.UserAccounts, "UserAccountID", "Email", suppliers.ModifiedBy);
            return(View(suppliers));
        }
        public ActionResult Create([Bind(Include = "ProductTypeID,ProductTypeName,DateCreated,DateModified,ModifiedBy")] ProductType productType)
        {
            if (ModelState.IsValid)
            {
                if (productType.DateCreated == null)
                {
                    productType.DateCreated = DateTime.Now;
                }
                if (productType.DateModified == null)
                {
                    productType.DateModified = DateTime.Now;
                }
                productType.ModifiedBy = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                db.ProductType.Add(productType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ModifiedBy = new SelectList(db.UserAccounts, "UserAccountID", "Email", productType.ModifiedBy);
            return(View(productType));
        }
        public ActionResult Create([Bind(Include = "StockID,ProductID,QuantityRemaining,DateCreated,DateModified,ModifiedBy")] Stock stock)
        {
            if (ModelState.IsValid)
            {
                if (stock.DateCreated == null)
                {
                    stock.DateCreated = DateTime.Now;
                }
                if (stock.DateModified == null)
                {
                    stock.DateModified = DateTime.Now;
                }
                stock.ModifiedBy = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                db.Stock.Add(stock);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductID  = new SelectList(db.Product, "ProductID", "ProductName", stock.ProductID);
            ViewBag.ModifiedBy = new SelectList(db.UserAccounts, "UserAccountID", "Email", stock.ModifiedBy);
            return(View(stock));
        }
Ejemplo n.º 15
0
 public bool update(InterventionType interventionType)
 {
     using (IMSEntities context = new IMSEntities())
     {
         var old = context.InterventionTypes.Where(i => i.Id == interventionType.Id).FirstOrDefault();
         context.Entry(old).CurrentValues.SetValues(interventionType);
         if (context.SaveChanges() > 0)
         {
             return(true);
         }
         return(false);
     }
 }
        public ActionResult Create([Bind(Include = "ProductID,ProductTypeID,ProductName,PricePerItem,Description,ThresholdQuantity,DateCreated,DateModified,ModifiedBy")] Product product)
        {
            if (ModelState.IsValid)
            {
                if (product.DateCreated == null)
                {
                    product.DateCreated = DateTime.Now;
                }
                if (product.DateModified == null)
                {
                    product.DateModified = DateTime.Now;
                }
                product.ModifiedBy = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                db.Product.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ModifiedBy    = new SelectList(db.UserAccounts, "UserAccountID", "Email", product.ModifiedBy);
            ViewBag.ProductTypeID = new SelectList(db.ProductType, "ProductTypeID", "ProductTypeName", product.ProductTypeID);
            return(View(product));
        }
        public ActionResult Create([Bind(Include = "UserDetailD,UserAccountID,FirstName,LastName,BirthDate,ContactNumber,Address,DateCreated,DateModified,ModifiedBy")] UserDetails userDetails)
        {
            if (ModelState.IsValid)
            {
                if (userDetails.DateCreated == null)
                {
                    userDetails.DateCreated = DateTime.Now;
                }
                if (userDetails.DateModified == null)
                {
                    userDetails.DateModified = DateTime.Now;
                }
                userDetails.ModifiedBy = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                db.UserDetails.Add(userDetails);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ModifiedBy    = new SelectList(db.UserAccounts, "UserAccountID", "Email", userDetails.ModifiedBy);
            ViewBag.UserAccountID = new SelectList(db.UserAccounts, "UserAccountID", "Email", userDetails.UserAccountID);
            return(View(userDetails));
        }
Ejemplo n.º 18
0
        public ActionResult Create([Bind(Include = "UserAccountID,UserTypeID,Email,Password,DateCreated,DateModified,ModifiedBy")] UserAccounts userAccounts)
        {
            if (ModelState.IsValid)
            {
                if (userAccounts.DateCreated == null)
                {
                    userAccounts.DateCreated = DateTime.Now;
                }
                if (userAccounts.DateModified == null)
                {
                    userAccounts.DateModified = DateTime.Now;
                }
                userAccounts.ModifiedBy = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                db.UserAccounts.Add(userAccounts);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ModifiedBy = new SelectList(db.UserAccounts, "UserAccountID", "Email", userAccounts.ModifiedBy);
            ViewBag.UserTypeID = new SelectList(db.UserType, "UserTypeID", "UserTypeName", userAccounts.UserTypeID);
            return(View(userAccounts));
        }
Ejemplo n.º 19
0
        public bool updateUser(User user)
        {
            using (IMSEntities context = new IMSEntities())
            {
                var old = context.Users.Where(u => u.Id == user.Id).FirstOrDefault();

                context.Entry(old).CurrentValues.SetValues(user);
                if (context.SaveChanges() > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
        public ActionResult Create([Bind(Include = "StockManagementID,StockID,OperationType,OperationDate,Quantity,UserAccountID,DateCreated,DateModified,ModifiedBy")] StockManagment stockManagment)
        {
            if (ModelState.IsValid)
            {
                if (stockManagment.DateCreated == null)
                {
                    stockManagment.DateCreated = DateTime.Now;
                }
                if (stockManagment.DateModified == null)
                {
                    stockManagment.DateModified = DateTime.Now;
                }
                stockManagment.ModifiedBy = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                db.StockManagment.Add(stockManagment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StockID       = new SelectList(db.Stock, "StockID", "StockID", stockManagment.StockID);
            ViewBag.ModifiedBy    = new SelectList(db.UserAccounts, "UserAccountID", "Email", stockManagment.ModifiedBy);
            ViewBag.UserAccountID = new SelectList(db.UserAccounts, "UserAccountID", "Email", stockManagment.UserAccountID);
            return(View(stockManagment));
        }
        public ActionResult Create([Bind(Include = "SalesID,BillingDate,BillingAmount,UserAccountID,DateCreated,DateModified,ModifiedBy")] Sales sales)
        {
            if (ModelState.IsValid)
            {
                if (sales.DateCreated == null)
                {
                    sales.DateCreated = DateTime.Now;
                }
                if (sales.DateModified == null)
                {
                    sales.DateModified = DateTime.Now;
                }
                sales.BillingAmount = 0;
                sales.ModifiedBy    = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                db.Sales.Add(sales);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ModifiedBy    = new SelectList(db.UserAccounts, "UserAccountID", "Email", sales.ModifiedBy);
            ViewBag.UserAccountID = new SelectList(db.UserAccounts, "UserAccountID", "Email", sales.UserAccountID);
            return(View(sales));
        }
Ejemplo n.º 22
0
        public ActionResult Create([Bind(Include = "ProductSupplierID,ProductID,SupplierID,DateCreated,DateModified,ModifiedBy")] ProductSupplier ProductSupplier)
        {
            if (ModelState.IsValid)
            {
                if (ProductSupplier.DateCreated == null)
                {
                    ProductSupplier.DateCreated = DateTime.Now;
                }
                if (ProductSupplier.DateModified == null)
                {
                    ProductSupplier.DateModified = DateTime.Now;
                }
                ProductSupplier.ModifiedBy = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
                db.ProductSupplier.Add(ProductSupplier);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductTypeID = new SelectList(db.ProductType, "ProductID", "ProductName", ProductSupplier.ProductID);
            ViewBag.ModifiedBy    = new SelectList(db.UserAccounts, "UserAccountID", "Email", ProductSupplier.ModifiedBy);
            ViewBag.SupplierID    = new SelectList(db.Suppliers, "SupplierID", "SupplierEmail", ProductSupplier.SupplierID);
            return(View(ProductSupplier));
        }
Ejemplo n.º 23
0
        public bool update(District district)
        {
            using (IMSEntities context = new IMSEntities())
            {
                //var old = context.Clients.Where(c => c.Id == client.Id).FirstOrDefault();
                var old = context.Districts.Find(district);
                context.Entry(old).CurrentValues.SetValues(district);

                if (context.SaveChanges() > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
        public ActionResult Delete(int AssetId)
        {
            if (AssetId > 0)
            {
                var Delete = Ims.tbl_AssetMaster.Where(a => a.AssetId == AssetId).FirstOrDefault();
                if (Delete != null)
                {
                    Ims.Entry(Delete).State = EntityState.Deleted;

                    int a = Ims.SaveChanges();
                    if (a > 0)
                    {
                        TempData["DeleteMesage"] = " <script>alert('Are You Sure You Want To Delete !')</Script>";

                        return(RedirectToAction("AssetMasterList"));
                    }
                    else
                    {
                        TempData["DeleteMesage"] = " <script>alert('Not Deleted')</Script>";
                    }
                }
            }
            return(View("AssetMasterList"));
        }
Ejemplo n.º 25
0
        public ActionResult Create(tbl_UserRegistration user)
        {
            try
            {
                if (ModelState.IsValid == true)
                {
                    //####### 1st Method for Insert Record In Database without extra column value #######//

                    //Ims.tbl_UserRegistration.Add(user);
                    //Ims.SaveChanges();
                    //ViewBag.Message = "Insert SuccessFull";

                    // ################################################################# //

                    //##### 2nd Method for Insert Record In database with Extra Column Value ######//

                    tbl_UserRegistration add = new tbl_UserRegistration();
                    add.UserName  = user.UserName;
                    add.Email     = user.Email;
                    add.Password  = user.Password;
                    add.CreatedOn = DateTime.Now;
                    Ims.tbl_UserRegistration.Add(add);
                    Ims.SaveChanges();
                    ViewBag.Message = "Insert SuccessFull Go to Login Page";

                    //###########################################################//
                }
                ModelState.Clear();
                // return RedirectToAction("Login", "Admin");
                return(View());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Edit(tbl_AssetMaster user)
        {
            if (ModelState.IsValid == true)
            {
                //Ims.Entry(user).State = EntityState.Modified;
                //int a = Ims.SaveChanges();
                //if (a > 0)
                //{
                //    TempData["UpdateMesage"] = " <script>alert('Asset Update SuccessFull')</Script>";
                //    return RedirectToAction("AssetMasterList");
                //}
                //else
                //{
                //    TempData["UpdateMessage"] = " <script>alert('Asset Not Update')</Script>";
                //}



                using (IMSEntities obj = new IMSEntities())
                {
                    tbl_AssetMaster asset = (from m in obj.tbl_AssetMaster
                                             where m.AssetId == user.AssetId
                                             select m).FirstOrDefault();

                    asset.UserName       = user.UserName;
                    asset.LocationId     = user.LocationId;
                    asset.Ram            = user.Ram;
                    asset.WarrantyStatus = user.WarrantyStatus;
                    asset.WindowKey      = user.WindowKey;

                    int e = obj.SaveChanges();
                    if (e > 0)
                    {
                        TempData["UpdateMesage"] = " <script>alert('Asset Update SuccessFull')</Script>";
                        return(RedirectToAction("AssetMasterList"));
                    }
                    else
                    {
                        TempData["UpdateMessage"] = " <script>alert('Asset Not Update')</Script>";
                    }
                }
            }
            //  return View("AssetMasterList");
            return(RedirectToAction("AssetMasterList"));
        }
Ejemplo n.º 27
0
 public bool ApproveIntervention(Intervention intervention)
 {
     using (IMSEntities context = new IMSEntities())
     {
         intervention = context.Interventions.Where(i => i.Id == intervention.Id).FirstOrDefault <Intervention>();
     }
     if (intervention != null)
     {
         intervention.State = 1;
     }
     using (IMSEntities dbcontext = new IMSEntities())
     {
         dbcontext.Entry(intervention).State = System.Data.Entity.EntityState.Modified;
         if (dbcontext.SaveChanges() > 0)
         {
             return(true);
         }
         return(false);
     }
 }
Ejemplo n.º 28
0
 public void Add(Tbl_Entity entity)
 {
     _dbSet.Add(entity);
     _DBEntity.SaveChanges();
 }
Ejemplo n.º 29
0
 public void SaveChangesToDb()
 {
     IMSDB.SaveChanges();
 }
Ejemplo n.º 30
0
 public void SaveChanges()
 {
     DBEntity.SaveChanges();
 }