Exemplo n.º 1
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "CarrierID,CarrierName,CarrierAddress,ContactName,CarrierPhone,CarrierMobile,CarrierEmail,Active,ModifiedDate,LastActive,CreatedDate")] Carrier carrier)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (carrier.CarrierID.Equals(0))
                    {
                        db.Carriers.Add(carrier);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        db.Entry(carrier).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                catch
                {
                    TempData["CustomError"] = "Carrier Name is not Unique";
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            return(View(carrier));
        }
        //   [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "TareWeight,LoadedWeight,Status,ActualWeight,ModifiedDate,ShipmentID,CreatedDate,VehicleCode,Ismanual")] WeighBridge weighBridge)
        {
            if (ModelState.IsValid)
            {
                WeighBridge _weighBridge = db.WeighBridges.Find(weighBridge.ShipmentID);
                Shipment    _Ship        = db.Shipments.Find(weighBridge.ShipmentID);
                if (_Ship.ShipmentStatusID == 2)
                {
                    _Ship.ShipmentStatusID = 3;
                    db.Entry(_Ship).State  = EntityState.Modified;
                }
                if (_Ship.ShipmentStatusID == 5)
                {
                    return(RedirectToAction("Index"));
                }

                WeighBridge WB = new WeighBridge();

                if (_weighBridge != null)
                {
                    _weighBridge.Status       = "Manual";
                    _weighBridge.LoadedWeight = weighBridge.LoadedWeight;
                    _weighBridge.TareWeight   = weighBridge.TareWeight;
                    _weighBridge.ActualWeight = weighBridge.ActualWeight;
                    _weighBridge.Ismanual     = true;
                    _weighBridge.VehicleCode  = weighBridge.VehicleCode;
                    _weighBridge.ModifiedDate = DateTime.Now;
                    _weighBridge.ModifiedBy   = User.Identity.Name;

                    if (ModelState.IsValid)
                    {
                        db.Entry(_weighBridge).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                else
                {
                    WB.Status       = "Manual";
                    WB.LoadedWeight = weighBridge.LoadedWeight;
                    WB.TareWeight   = weighBridge.TareWeight;
                    WB.ActualWeight = weighBridge.ActualWeight;
                    WB.Ismanual     = true;
                    WB.VehicleCode  = weighBridge.VehicleCode;
                    WB.ShipmentID   = weighBridge.ShipmentID;
                    WB.CreatedDate  = DateTime.Now;
                    WB.CreatedBy    = User.Identity.Name;
                    WB.ModifiedDate = DateTime.Now;
                    WB.ModifiedBy   = User.Identity.Name;
                    db.WeighBridges.Add(WB);

                    db.SaveChanges();
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            return(RedirectToAction("Index"));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "CompartmentID,CompartmentCode,Capactiy,TrailerID,Description,ModifiedDate,CreatedDate")] Compartment compartment)
        {
            if (ModelState.IsValid)
            {
                if (compartment.CompartmentID.Equals(0))
                {
                    db.Compartments.Add(compartment);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new
                    {
                        ID = compartment.TrailerID
                    }));
                }
                else
                {
                    db.Entry(compartment).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new
                    {
                        ID = compartment.TrailerID
                    }));
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            ViewBag.TrailerID = new SelectList(db.Trailers, "TrailerID", "TrailerCode", compartment.TrailerID);
            return(View(compartment));
        }
Exemplo n.º 4
0
        // [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "TrailerID,TrailerCode,LoadingType,VehicleID,ModifiedDate,CreatedDate")] Trailer trailer)
        {
            if (ModelState.IsValid)
            {
                if (trailer.TrailerID.Equals(0))
                {
                    db.Trailers.Add(trailer);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new
                    {
                        ID = trailer.VehicleID
                    }));
                }
                else
                {
                    db.Entry(trailer).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new
                    {
                        ID = trailer.VehicleID
                    }));
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            ViewBag.VehicleID = new SelectList(db.Vehicles, "VehicleID", "VehicleCode", trailer.VehicleID);
            return(View(trailer));
        }
Exemplo n.º 5
0
 // [ValidateAntiForgeryToken]
 public ActionResult Create([Bind(Include = "DriverID,DriverName,LicenseNo,LicenseIDate,LicenseEDate,CNIC,Mobile,Active,LastActive,Remarks,CarrierID,CreatedDate,ModifiedDate")] Driver driver)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (driver.DriverID.Equals(0))
             {
                 db.Drivers.Add(driver);
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
             else
             {
                 db.Entry(driver).State = EntityState.Modified;
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
         }
         catch
         {
             TempData["CustomError"] = "Driver CNIC not Unique";
             return(RedirectToAction("Index"));
         }
     }
     ViewBag.CarrierID = new SelectList(db.Carriers, "CarrierID", "CarrierName", driver.CarrierID);
     return(View(driver));
 }
Exemplo n.º 6
0
 // [ValidateAntiForgeryToken]
 public ActionResult Edit([Bind(Include = "BayID,Frequency,CurrQueue,Active,LastActive,Remarks,ProductID")] Bay bay)
 {
     if (ModelState.IsValid)
     {
         bay.ModifiedDate    = DateTime.Now;
         bay.ModifiedBy      = User.Identity.Name;
         db.Entry(bay).State = EntityState.Modified;
         db.Entry(bay).Property(x => x.CreatedDate).IsModified = false;
         db.Entry(bay).Property(x => x.CreatedBy).IsModified   = false;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", bay.ProductID);
     return(View(bay));
 }
Exemplo n.º 7
0
 //[ValidateAntiForgeryToken]
 public ActionResult Create([Bind(Include = "VehicleID,VehicleCode,LicenseNo,LicenseIDate,LicenseEDate,Active,LastActive,Remarks,CarrierID,DriverID")] Vehicle vehicle)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (vehicle.VehicleID.Equals(0))
             {
                 vehicle.CreatedDate  = DateTime.Now;
                 vehicle.CreatedBy    = User.Identity.Name;
                 vehicle.ModifiedDate = DateTime.Now;
                 vehicle.ModifiedBy   = User.Identity.Name;
                 db.Vehicles.Add(vehicle);
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
             else
             {
                 vehicle.ModifiedDate    = DateTime.Now;
                 vehicle.ModifiedBy      = User.Identity.Name;
                 db.Entry(vehicle).State = EntityState.Modified;
                 db.Entry(vehicle).Property(x => x.CreatedDate).IsModified = false;
                 db.Entry(vehicle).Property(x => x.CreatedBy).IsModified   = false;
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
         }
         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);
                 }
             }
             TempData["CustomError"] = "Vehicle Code is not Unique";
             return(RedirectToAction("Index"));
         }
     }
     ViewBag.CarrierID = new SelectList(db.Carriers, "CarrierID", "CarrierName", vehicle.CarrierID);
     ViewBag.DriverID  = new SelectList(db.Drivers, "DriverID", "DriverName", vehicle.DriverID);
     return(View(vehicle));
 }
Exemplo n.º 8
0
 // [ValidateAntiForgeryToken]
 public ActionResult Edit([Bind(Include = "BayID,Frequency,CurrQueue,Active,LastActive,Remarks,ModifiedDate,CreatedDate,ProductID")] Bay bay)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bay).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", bay.ProductID);
     return(View(bay));
 }
Exemplo n.º 9
0
        // [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "TrailerID,TrailerCode,LoadingType,VehicleID,BowserCalibrationCertificate,CertificateExpiryDate")] Trailer trailer)
        {
            if (ModelState.IsValid)
            {
                if (trailer.TrailerID.Equals(0))
                {
                    trailer.CreatedDate  = DateTime.Now;
                    trailer.CreatedBy    = User.Identity.Name;
                    trailer.ModifiedDate = DateTime.Now;
                    trailer.ModifiedBy   = User.Identity.Name;
                    db.Trailers.Add(trailer);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new
                    {
                        ID = trailer.VehicleID
                    }));
                }
                else
                {
                    trailer.ModifiedDate    = DateTime.Now;
                    trailer.ModifiedBy      = User.Identity.Name;
                    db.Entry(trailer).State = EntityState.Modified;
                    db.Entry(trailer).Property(x => x.CreatedDate).IsModified = false;
                    db.Entry(trailer).Property(x => x.CreatedBy).IsModified   = false;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new
                    {
                        ID = trailer.VehicleID
                    }));
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            ViewBag.VehicleID = new SelectList(db.Vehicles, "VehicleID", "VehicleCode", trailer.VehicleID);
            return(View(trailer));
        }
Exemplo n.º 10
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "CompartmentID,CompartmentCode,Capactiy,TrailerID,Description,ChamberDipMM")] Compartment compartment)
        {
            if (ModelState.IsValid)
            {
                if (compartment.CompartmentID.Equals(0))
                {
                    compartment.CreatedDate  = DateTime.Now;
                    compartment.CreatedBy    = User.Identity.Name;
                    compartment.ModifiedDate = DateTime.Now;
                    compartment.ModifiedBy   = User.Identity.Name;
                    db.Compartments.Add(compartment);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new
                    {
                        ID = compartment.TrailerID
                    }));
                }
                else
                {
                    compartment.ModifiedDate    = DateTime.Now;
                    compartment.ModifiedBy      = User.Identity.Name;
                    db.Entry(compartment).State = EntityState.Modified;
                    db.Entry(compartment).Property(x => x.CreatedDate).IsModified = false;
                    db.Entry(compartment).Property(x => x.CreatedBy).IsModified   = false;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new
                    {
                        ID = compartment.TrailerID
                    }));
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            ViewBag.TrailerID = new SelectList(db.Trailers, "TrailerID", "TrailerCode", compartment.TrailerID);
            return(View(compartment));
        }
Exemplo n.º 11
0
 // [ValidateAntiForgeryToken]
 public ActionResult Edit([Bind(Include = "ProductID,ProductName,WeighOut,Active,LastActive,Remarks")] Product product)
 {
     if (ModelState.IsValid)
     {
         //foreach (var entry in db.ChangeTracker.Entries().Where(x => x.Entity.GetType().GetProperty("CreatedDate") != null))
         //{
         //    entry.Property("CreatedDate").IsModified = false;
         //}
         product.ModifiedDate    = DateTime.Now;
         product.ModifiedBy      = User.Identity.Name;
         db.Entry(product).State = EntityState.Modified;
         db.Entry(product).Property(x => x.CreatedDate).IsModified = false;
         db.Entry(product).Property(x => x.CreatedBy).IsModified   = false;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         var errors = ModelState.Values.SelectMany(v => v.Errors);
     }
     return(View(product));
 }
Exemplo n.º 12
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "CustomerID,CustomerName,CustomerAddress,ContactName,CustomerPhone,CustomerMobile,CustomerEmail,Active")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (customer.CustomerID.Equals(0))
                    {
                        customer.CreatedDate  = DateTime.Now;
                        customer.CreatedBy    = User.Identity.Name;
                        customer.ModifiedDate = DateTime.Now;
                        customer.ModifiedBy   = User.Identity.Name;
                        db.Customers.Add(customer);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        customer.ModifiedDate    = DateTime.Now;
                        customer.ModifiedBy      = User.Identity.Name;
                        db.Entry(customer).State = EntityState.Modified;
                        db.Entry(customer).Property(x => x.CreatedDate).IsModified = false;
                        db.Entry(customer).Property(x => x.CreatedBy).IsModified   = false;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                catch
                {
                    TempData["CustomError"] = "Customer Name is not Unique";
                    return(RedirectToAction("Index"));
                }
            }

            return(View(customer));
        }
Exemplo n.º 13
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(AccessCard accessCard)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (accessCard.CardID.Equals(0))
                    {
                        db.AccessCards.Add(accessCard);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        accessCard.ModifiedDate = DateTime.Now;
                        accessCard.ModifiedBy   = User.Identity.Name;
                        db.AccessCards.Attach(accessCard);
                        db.Entry(accessCard).Property(x => x.BayID).IsModified        = true;
                        db.Entry(accessCard).Property(x => x.Remarks).IsModified      = true;
                        db.Entry(accessCard).Property(x => x.Active).IsModified       = true;
                        db.Entry(accessCard).Property(x => x.IsAssigned).IsModified   = true;
                        db.Entry(accessCard).Property(x => x.ModifiedDate).IsModified = true;
                        db.Entry(accessCard).Property(x => x.ModifiedBy).IsModified   = true;
                        //db.Entry(accessCard).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                catch
                {
                    TempData["CustomError"] = "Card ID is not Unique";
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.BayID = new SelectList(db.Bays, "BayID", "Remarks", accessCard.BayID);
            return(View(accessCard));
        }
Exemplo n.º 14
0
        // [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "DriverID,DriverName,LicenseNo,LicenseIDate,LicenseEDate,CNIC,Mobile,Active,LastActive,Remarks,CarrierID")] Driver driver, byte[] RowVersion)
        {
            string[] fieldsToBind = { "DriverID", "DriverName", "LicenseNo", "LicenseIDate", "LicenseEDate", "CNIC", "Mobile", "Active", "LastActive", "Remarks", "CarrierID" };
            if (ModelState.IsValid)
            {
                try
                {
                    if (driver.DriverID.Equals(0))
                    {
                        driver.CreatedDate  = DateTime.Now;
                        driver.CreatedBy    = User.Identity.Name;
                        driver.ModifiedDate = DateTime.Now;
                        driver.ModifiedBy   = User.Identity.Name;
                        db.Drivers.Add(driver);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        //driver.ModifiedDate = DateTime.Now;
                        //driver.ModifiedBy = User.Identity.Name;
                        //db.Entry(driver).State = EntityState.Modified;
                        //db.Entry(driver).Property(x => x.CreatedDate).IsModified = false;
                        //db.Entry(driver).Property(x => x.CreatedBy).IsModified = false;
                        //db.SaveChanges();
                        //return RedirectToAction("Index");

                        var driverToUpdate = db.Drivers.Find(driver.DriverID);
                        if (driverToUpdate == null)
                        {
                            //AccessCard accessCardDeleted = new AccessCard();
                            //TryUpdateModel(accessCardDeleted, fieldsToBind);
                            ModelState.AddModelError(string.Empty, "Unable to save changes. The record was deleted by another user.");
                            return(RedirectToAction("Index"));
                        }
                        if (TryUpdateModel(driverToUpdate, fieldsToBind))
                        {
                            string UpdatedUser = string.Empty;
                            try
                            {
                                UpdatedUser = driverToUpdate.ModifiedBy;
                                driverToUpdate.ModifiedDate    = DateTime.Now;
                                driverToUpdate.ModifiedBy      = User.Identity.Name;
                                db.Entry(driverToUpdate).State = EntityState.Modified;
                                db.Entry(driverToUpdate).Property(x => x.CreatedDate).IsModified = false;
                                db.Entry(driverToUpdate).Property(x => x.CreatedBy).IsModified   = false;
                                db.Entry(driverToUpdate).OriginalValues["RowVersion"]            = RowVersion;
                                db.SaveChanges();
                                return(RedirectToAction("Index"));
                            }
                            catch (DbUpdateConcurrencyException ex)
                            {
                                var entry         = ex.Entries.Single();
                                var clientValues  = (Driver)entry.Entity;
                                var databaseEntry = entry.GetDatabaseValues();
                                if (databaseEntry == null)
                                {
                                    TempData["ErrorMessage"] = "Unable to save changes. The record was deleted";
                                }
                                else
                                {
                                    TempData["ErrorMessage"] = "Unable to save changes. The record was edited by " + UpdatedUser + ". Select Updated Record.";
                                }
                            }
                        }
                        return(RedirectToAction("Index"));
                    }
                }
                catch
                {
                    TempData["CustomError"] = "Driver CNIC not Unique";
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.CarrierID = new SelectList(db.Carriers, "CarrierID", "CarrierName", driver.CarrierID);
            return(View(driver));
        }
Exemplo n.º 15
0
        // [ValidateAntiForgeryToken]
        //public ActionResult Edit([Bind(Include = "ProductID,ProductName,WeighOut,Active,LastActive,Remarks")] Product product)
        public async Task <ActionResult> Edit(int?ProductID, byte[] RowVersion)
        {
            string[] fieldsToBind = new string[] { "ProductID", "ProductName", "WeighOut", "Active", "LastActive", "Remarks" };
            if (ProductID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (ModelState.IsValid)
            {
                Product product = new Product();
                //customer.CustomerID.Equals(0)
                if (ProductID.Equals(0) && TryUpdateModel(product, fieldsToBind))
                {
                    product.CreatedBy    = User.Identity.Name;
                    product.ModifiedBy   = User.Identity.Name;
                    product.CreatedDate  = DateTime.Now;
                    product.ModifiedDate = DateTime.Now;
                    db.Products.Add(product);
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                var productToUpdate = await db.Products.FindAsync(ProductID);

                if (productToUpdate == null)
                {
                    Product productDeleted = new Product();
                    TryUpdateModel(productDeleted, fieldsToBind);
                    ModelState.AddModelError(string.Empty, "Unable to save changes. The product was deleted by another user.");
                    return(View(productDeleted));
                }
                if (TryUpdateModel(productToUpdate, fieldsToBind))
                {
                    string UpdatedUser = string.Empty;
                    try
                    {
                        UpdatedUser = productToUpdate.ModifiedBy;
                        productToUpdate.ModifiedDate = DateTime.Now;
                        productToUpdate.ModifiedBy   = User.Identity.Name;
                        db.Entry(productToUpdate).Property(x => x.CreatedDate).IsModified = false;
                        db.Entry(productToUpdate).Property(x => x.CreatedBy).IsModified   = false;
                        db.Entry <Product>(productToUpdate).State = EntityState.Modified;
                        db.Entry(productToUpdate).OriginalValues["RowVersion"] = RowVersion;
                        await db.SaveChangesAsync();

                        return(RedirectToAction("Index"));
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        var entry         = ex.Entries.Single();
                        var clientValues  = (Product)entry.Entity;
                        var databaseEntry = entry.GetDatabaseValues();
                        if (databaseEntry == null)
                        {
                            TempData["ErrorMessage"] = "Unable to save changes. The record was deleted";
                        }
                        else
                        {
                            TempData["ErrorMessage"] = "Unable to save changes. The record was edited by " + UpdatedUser + ". Select Updated Record.";
                        }
                    }
                }
            }
            //    product.ModifiedDate = DateTime.Now;
            //product.ModifiedBy = User.Identity.Name;
            //db.Entry(product).State = EntityState.Modified;
            //db.Entry(product).Property(x => x.CreatedDate).IsModified = false;
            //db.Entry(product).Property(x => x.CreatedBy).IsModified = false;
            //db.SaveChanges();
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }
            //return View(product);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 16
0
        public void bayFrequency(int bayId)
        {
            Bay bay = db.Bays.Where(x => x.BayID == bayId).FirstOrDefault <Bay>();

            bay.Frequency = bay.Frequency + 1;
            db.Bays.Attach(bay);
            db.Entry(bay).Property(x => x.Frequency).IsModified = true;
            db.SaveChanges();
        }
Exemplo n.º 17
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "CustomerID,CustomerName,CustomerAddress,ContactName,CustomerPhone,CustomerMobile,CustomerEmail,Active,CNIC")] Customer customer, byte[] RowVersion, HttpPostedFileBase file)
        {
            string[] fieldsToBind = { "CustomerID", "CustomerName", "CustomerAddress", "ContactName", "CustomerPhone", "CustomerMobile", "CustomerEmail", "Active", "CNIC" };
            if (ModelState.IsValid)
            {
                try
                {
                    if (customer.CustomerID.Equals(0))
                    {
                        customer.CreatedDate  = DateTime.Now;
                        customer.CreatedBy    = User.Identity.Name;
                        customer.ModifiedDate = DateTime.Now;
                        customer.ModifiedBy   = User.Identity.Name;
                        if (file != null)
                        {
                            customer.SignatureImagePath = getCustImagePath(file);
                        }
                        db.Customers.Add(customer);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        var customerToUpdate = db.Customers.Find(customer.CustomerID);
                        if (customerToUpdate == null)
                        {
                            //AccessCard accessCardDeleted = new AccessCard();
                            //TryUpdateModel(accessCardDeleted, fieldsToBind);
                            ModelState.AddModelError(string.Empty, "Unable to save changes. The record was deleted by another user.");
                            return(RedirectToAction("Index"));
                        }
                        if (TryUpdateModel(customerToUpdate, fieldsToBind))
                        {
                            string UpdatedUser = string.Empty;
                            try
                            {
                                UpdatedUser = customerToUpdate.ModifiedBy;

                                customerToUpdate.ModifiedDate = DateTime.Now;
                                customerToUpdate.ModifiedBy   = User.Identity.Name;
                                if (file != null)
                                {
                                    //if file is not null means user changed the signature file so we have to savve the new one else the same
                                    customerToUpdate.SignatureImagePath = getCustImagePath(file);
                                }
                                db.Entry(customerToUpdate).State = EntityState.Modified;
                                db.Entry(customerToUpdate).Property(x => x.CreatedDate).IsModified = false;
                                db.Entry(customerToUpdate).Property(x => x.CreatedBy).IsModified   = false;

                                db.Entry(customerToUpdate).OriginalValues["RowVersion"] = RowVersion;

                                db.SaveChanges();
                                return(RedirectToAction("Index"));
                            }
                            catch (DbUpdateConcurrencyException ex)
                            {
                                var entry         = ex.Entries.Single();
                                var clientValues  = (Customer)entry.Entity;
                                var databaseEntry = entry.GetDatabaseValues();
                                if (databaseEntry == null)
                                {
                                    TempData["ErrorMessage"] = "Unable to save changes. The record was deleted";
                                }
                                else
                                {
                                    TempData["ErrorMessage"] = "Unable to save changes. The record was edited by " + UpdatedUser + ". Select Updated Record.";
                                }
                            }
                        }
                        return(RedirectToAction("Index"));
                    }
                }
                catch
                {
                    TempData["CustomError"] = "Customer Name is not Unique";
                    return(RedirectToAction("Index"));
                }
            }

            return(View(customer));
        }
Exemplo n.º 18
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "VehicleID,VehicleCode,LicenseNo,LicenseIDate,LicenseEDate,Active,LastActive,Remarks,CarrierID,DriverID,RowVersionInt")] Vehicle vehicle)
        //public ActionResult Create(int? VehicleID, byte[] RowVersion)
        {
            Vehicle tempVehicle = db.Vehicles.AsNoTracking().FirstOrDefault(x => x.VehicleID == vehicle.VehicleID);// db.Vehicles.FindAsync(vehicle.VehicleID);

            string[] fieldsToBind = { "VehicleID", "VehicleCode", "LicenseNo", "LicenseIDate", "LicenseEDate", "Active", "LastActive", "Remarks", "CarrierID", "DriverID", "RowVersion" };
            //byte[] rowVersion = vehicle.RowVersion;
            //var vehicleToUpdate = db.Vehicles.Find(vehicle.VehicleID);
            //if (vehicleToUpdate == null)
            //{
            //    vehicleToUpdate.CreatedDate = DateTime.Now;
            //    vehicleToUpdate.CreatedBy = User.Identity.Name;
            //    vehicleToUpdate.ModifiedDate = DateTime.Now;
            //    vehicleToUpdate.ModifiedBy = User.Identity.Name;
            //    db.Vehicles.Add(vehicleToUpdate);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //    //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            if (ModelState.IsValid)
            {
                try
                {
                    if (vehicle.VehicleID.Equals(0))
                    //if (vehicleToUpdate == null)
                    {
                        vehicle.CreatedDate   = DateTime.Now;
                        vehicle.CreatedBy     = User.Identity.Name;
                        vehicle.ModifiedDate  = DateTime.Now;
                        vehicle.ModifiedBy    = User.Identity.Name;
                        vehicle.RowVersionInt = 0;
                        db.Vehicles.Add(vehicle);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        //var vehicleToUpdate = db.Vehicles.FirstOrDefault(i => i.VehicleID == vehicle.VehicleID);

                        //////
                        //db.Entry<Vehicle>(vehicleToUpdate).State = EntityState.Modified;
                        //vehicleToUpdate.ModifiedDate = DateTime.Now;
                        //vehicleToUpdate.ModifiedBy = User.Identity.Name;

                        //vehicleToUpdate.VehicleCode= "aaa111" ;


                        //db.Entry<Bay>(bayToUpdate).State = EntityState.Modified;

                        //db.Entry(vehicleToUpdate).Property(x => x.CreatedDate).IsModified = false;
                        //db.Entry(vehicleToUpdate).Property(x => x.CreatedBy).IsModified = false;


                        //db.Entry<Vehicle>(vehicleToUpdate).State = EntityState.Detached;

                        //TryUpdateModel(vehicleToUpdate, fieldsToBind);
                        //db.Entry(vehicleToUpdate).CurrentValues.SetValues(vehicle);
                        //db.Entry<Vehicle>(vehicleToUpdate).State = EntityState.Modified;
                        //db.Entry(vehicleToUpdate).OriginalValues["RowVersion"] = RowVersion;

                        //
                        //Old code below


                        //vehicle.ModifiedDate = DateTime.Now;
                        //vehicle.ModifiedBy = User.Identity.Name;
                        //db.Entry(vehicle).State = EntityState.Modified;
                        //db.Entry(vehicle).Property(x => x.CreatedDate).IsModified = false;
                        //db.Entry(vehicle).Property(x => x.CreatedBy).IsModified = false;

                        //db.Entry(vehicle).Property(x => x.VehicleID).IsModified = false;

                        //db.SaveChanges();
                        //return RedirectToAction("Index");
                        //old code ended


                        vehicle.ModifiedDate    = DateTime.Now;
                        vehicle.ModifiedBy      = User.Identity.Name;
                        db.Entry(vehicle).State = EntityState.Modified;
                        db.Entry(vehicle).Property(x => x.CreatedDate).IsModified = false;
                        db.Entry(vehicle).Property(x => x.CreatedBy).IsModified   = false;

                        //    db.Entry(vehicle).Property(x => x.VehicleID).IsModified = false;

                        //db.Entry(vehicle).Property(X => X.RowVersion).OriginalValue = rowVersion;

                        //db.Entry(vehicle).OriginalValues["RowVersion"] = rowVersion;
                        //var tempVehicle = db.Vehicles.Where(x => x.VehicleID == vehicle.VehicleID);

                        if (vehicle.RowVersionInt == null)
                        {
                            vehicle.RowVersionInt = 0;
                        }
                        if (tempVehicle == null)
                        {
                            TempData["ErrorMessage"] = "Unable to save changes. The record was deleted";
                            return(RedirectToAction("Index"));
                        }
                        if (tempVehicle.RowVersionInt != vehicle.RowVersionInt)
                        {
                            TempData["ErrorMessage"] = "Unable to save changes. The record was edited by " + tempVehicle.ModifiedBy + ". Select Updated Record.";
                            return(RedirectToAction("Index"));
                        }
                        vehicle.RowVersionInt++;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                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);
                        }
                    }
                    TempData["CustomError"] = "Vehicle Code is not Unique";
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.CarrierID = new SelectList(db.Carriers, "CarrierID", "CarrierName", vehicle.CarrierID);
            ViewBag.DriverID  = new SelectList(db.Drivers, "DriverID", "DriverName", vehicle.DriverID);
            return(View(vehicle));
        }
Exemplo n.º 19
0
        // [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "OrderID,OrderDate,OrderQty,RemainQty,CustomerID,ProductID,OrderCode,DeletedFlag,CarrierID,VehicleID,OrderStatusID,OrderDeliveryDT")] Order order, FormCollection formCollection)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (order.OrderID.Equals(0))
                    {
                        var shipment = new Shipment()
                        {
                            ProductID        = order.ProductID,
                            IsManual         = false,
                            CreatedDate      = DateTime.Now,
                            CreatedBy        = User.Identity.Name,
                            ModifiedDate     = DateTime.Now,
                            ModifiedBy       = User.Identity.Name,
                            ShipmentStatusID = 1,
                            OrderID          = order.OrderID,
                            CustomerName     = formCollection["Customer.CustomerName"],
                            CarrierName      = formCollection["Carrier.CarrierName"],
                            VehicleCode      = formCollection["Vehicle.VehicleCode"],
                            DriverName       = formCollection["Vehicle.Driver.DriverName"],
                            DriverCNIC       = formCollection["Vehicle.Driver.CNIC"]
                        };
                        ///////////////////////////////////////////////////////////////
                        order.CreatedDate  = DateTime.Now;
                        order.CreatedBy    = User.Identity.Name;
                        order.ModifiedDate = DateTime.Now;
                        order.ModifiedBy   = User.Identity.Name;
                        db.Orders.Add(order);
                        //////////////////////////////////////////////////////////////
                        db.Shipments.Add(shipment);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        Shipment ship = db.Shipments.Where(x => x.OrderID == order.OrderID).FirstOrDefault <Shipment>();
                        ship.ModifiedDate = DateTime.Now;
                        ship.ModifiedBy   = User.Identity.Name;
                        ship.CustomerName = formCollection["Customer.CustomerName"];
                        ship.CarrierName  = formCollection["Carrier.CarrierName"];
                        ship.VehicleCode  = formCollection["Vehicle.VehicleCode"];
                        ship.DriverName   = formCollection["Vehicle.Driver.DriverName"];
                        ship.DriverCNIC   = formCollection["Vehicle.Driver.CNIC"];
                        ship.ProductID    = order.ProductID;
                        db.Shipments.Attach(ship);
                        db.Entry(ship).Property(x => x.ModifiedDate).IsModified = true;
                        db.Entry(ship).Property(x => x.ModifiedBy).IsModified   = true;
                        db.Entry(ship).Property(x => x.CustomerName).IsModified = true;
                        db.Entry(ship).Property(x => x.CarrierName).IsModified  = true;
                        db.Entry(ship).Property(x => x.VehicleCode).IsModified  = true;
                        db.Entry(ship).Property(x => x.DriverName).IsModified   = true;
                        db.Entry(ship).Property(x => x.DriverCNIC).IsModified   = true;
                        db.Entry(ship).Property(x => x.ProductID).IsModified    = true;
                        db.Entry(ship).State = EntityState.Modified;
                        /////////////////////////////////////////////////////////////////////////////////////
                        order.ModifiedDate    = DateTime.Now;
                        order.ModifiedBy      = User.Identity.Name;
                        db.Entry(order).State = EntityState.Modified;
                        db.Entry(order).Property(x => x.CreatedDate).IsModified = false;
                        db.Entry(order).Property(x => x.CreatedBy).IsModified   = false;
                        ////////////////////////////////////////////////////////////////////////////////////
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    var errors = ModelState.Values.SelectMany(v => v.Errors);
                }
            }
            catch
            {
                TempData["CustomError"] = "Order Code is not Unique";
                return(RedirectToAction("Index"));
            }

            ViewBag.CarrierID     = new SelectList(db.Carriers, "CarrierID", "CarrierName", order.CarrierID);
            ViewBag.CustomerID    = new SelectList(db.Customers, "CustomerID", "CustomerName", order.CustomerID);
            ViewBag.ProductID     = new SelectList(db.Products, "ProductID", "ProductName", order.ProductID);
            ViewBag.OrderStatusID = new SelectList(db.OrderStatus, "ID", "Status", order.OrderStatusID);
            ViewBag.VehicleID     = new SelectList(db.Vehicles, "VehicleID", "VehicleCode", order.VehicleID);
            return(View(order));
        }
Exemplo n.º 20
0
        // [ValidateAntiForgeryToken]
        //public ActionResult Edit([Bind(Include = "BayID,Frequency,CurrQueue,Active,LastActive,Remarks,ProductID")] Bay bay)
        public async Task <ActionResult> Edit(int?BayID, byte[] RowVersion, string[] ddlProduct)
        {
            if (ddlProduct == null)
            {
                TempData["ErrorMessage"] = "Please select the Product first.";
                return(RedirectToAction("Index"));
            }
            string[] fieldsToBind = new string[] { "BayID", "Frequency", "CurrQueue", "Active", "LastActive", "Remarks", "ProductID" };
            if (BayID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (ModelState.IsValid)
            {
                var bayToUpdate = await db.Bays.FindAsync(BayID);

                var productID = Request["Frequency"].ToString();
                if (productID.Equals("-1"))
                {
                    Bay bayProduct = new Bay();
                    TryUpdateModel(bayProduct, fieldsToBind);

                    bayProduct.Frequency    = 0;
                    bayProduct.CurrQueue    = 0;
                    bayProduct.CreatedDate  = DateTime.Now;
                    bayProduct.ModifiedDate = DateTime.Now;
                    bayProduct.CreatedBy    = User.Identity.Name;
                    bayProduct.ModifiedBy   = User.Identity.Name;
                    db.Bays.Add(bayProduct);
                    db.SaveChanges();
                }
                else if (bayToUpdate == null)
                {
                    Bay productDeleted = new Bay();
                    TryUpdateModel(productDeleted, fieldsToBind);
                    ModelState.AddModelError(string.Empty, "Unable to save changes. The product was deleted by another user.");
                    //return View(productDeleted);
                    return(RedirectToAction("Index"));
                }
                if (bayToUpdate != null)
                {
                    TryUpdateModel(bayToUpdate, fieldsToBind);
                    string UpdatedUser = string.Empty;
                    try
                    {
                        //string strDDLValue = Request.Form["ddlVendor"].ToString();
                        bayToUpdate.ProductID    = Convert.ToInt32(ddlProduct[0]); //Convert.ToInt32(Request["ddlProduct"].ToString());
                        UpdatedUser              = bayToUpdate.ModifiedBy;
                        bayToUpdate.ModifiedDate = DateTime.Now;
                        bayToUpdate.ModifiedBy   = User.Identity.Name;
                        db.Entry(bayToUpdate).Property(x => x.CreatedDate).IsModified = false;
                        db.Entry(bayToUpdate).Property(x => x.CreatedBy).IsModified   = false;
                        db.Entry <Bay>(bayToUpdate).State = EntityState.Modified;
                        db.Entry(bayToUpdate).OriginalValues["RowVersion"] = RowVersion;
                        await db.SaveChangesAsync();

                        return(RedirectToAction("Index"));
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        var entry         = ex.Entries.Single();
                        var clientValues  = (Bay)entry.Entity;
                        var databaseEntry = entry.GetDatabaseValues();
                        if (databaseEntry == null)
                        {
                            TempData["ErrorMessage"] = "Unable to save changes. The record was deleted";
                        }
                        else
                        {
                            TempData["ErrorMessage"] = "Unable to save changes. The record was edited by " + UpdatedUser + ". Select Updated Record.";
                        }
                    }
                }
                //bay.ModifiedDate = DateTime.Now;
                //bay.ModifiedBy = User.Identity.Name;
                //db.Entry(bay).State = EntityState.Modified;
                //db.Entry(bay).Property(x => x.CreatedDate).IsModified = false;
                //db.Entry(bay).Property(x => x.CreatedBy).IsModified = false;
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            //ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", bay.ProductID);
            //return View(bay);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 21
0
        public void setCurrQueue()
        {
            var queuedShiments = from x in db.Shipments
                                 where x.ShipmentStatusID == 2
                                 orderby x.BayID
                                 group x by x.BayID into grp
                                 select new { BayID = grp.Select(y => y.BayID).Distinct().FirstOrDefault().Value, count = grp.Count() };


            var queueCount = (from b in db.Bays
                              select new
            {
                ID = b.BayID, Queue = 0
            }).AsEnumerable().Select(x => new Bay {
                BayID     = x.ID,
                CurrQueue = x.Queue
            }).ToList();


            foreach (var ship in queuedShiments)
            {
                queueCount.Where(x => x.BayID == ship.BayID).FirstOrDefault().CurrQueue = ship.count;
            }
            foreach (var bayNo in queueCount)
            {
                Bay bay = db.Bays.Where(x => x.BayID == bayNo.BayID).FirstOrDefault <Bay>();
                bay.ModifiedDate = DateTime.Now;
                bay.CurrQueue    = bayNo.CurrQueue;
                db.Bays.Attach(bay);
                db.Entry(bay).Property(x => x.ModifiedDate).IsModified = true;
                db.Entry(bay).Property(x => x.CurrQueue).IsModified    = true;
            }
            db.SaveChanges();
        }
Exemplo n.º 22
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "CarrierID,CarrierName,CarrierAddress,ContactName,CarrierPhone,CarrierMobile,CarrierEmail,Active,LastActive,Remarks")] Carrier carrier, byte[] RowVersion)
        {
            string[] fieldsToBind = { "CarrierID", "CarrierName", "CarrierAddress", "ContactName", "CarrierPhone", "CarrierMobile", "CarrierEmail", "Active", "LastActive", "Remarks" };
            if (ModelState.IsValid)
            {
                try
                {
                    if (carrier.CarrierID.Equals(0))
                    {
                        carrier.CreatedDate  = DateTime.Now;
                        carrier.CreatedBy    = User.Identity.Name;
                        carrier.ModifiedDate = DateTime.Now;
                        carrier.ModifiedBy   = User.Identity.Name;
                        db.Carriers.Add(carrier);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        //carrier.ModifiedDate = DateTime.Now;
                        //carrier.ModifiedBy = User.Identity.Name;
                        //db.Entry(carrier).State = EntityState.Modified;
                        //db.Entry(carrier).Property(x => x.CreatedDate).IsModified = false;
                        //db.Entry(carrier).Property(x => x.CreatedBy).IsModified = false;
                        //db.SaveChanges();
                        //return RedirectToAction("Index");
                        var carrierToUpdate = db.Carriers.Find(carrier.CarrierID);
                        if (carrierToUpdate == null)
                        {
                            //AccessCard accessCardDeleted = new AccessCard();
                            //TryUpdateModel(accessCardDeleted, fieldsToBind);
                            ModelState.AddModelError(string.Empty, "Unable to save changes. The record was deleted by another user.");
                            return(RedirectToAction("Index"));
                        }
                        if (TryUpdateModel(carrierToUpdate, fieldsToBind))
                        {
                            string UpdatedUser = string.Empty;
                            try
                            {
                                UpdatedUser = carrierToUpdate.ModifiedBy;
                                carrierToUpdate.ModifiedDate    = DateTime.Now;
                                carrierToUpdate.ModifiedBy      = User.Identity.Name;
                                db.Entry(carrierToUpdate).State = EntityState.Modified;
                                db.Entry(carrierToUpdate).Property(x => x.CreatedDate).IsModified = false;
                                db.Entry(carrierToUpdate).Property(x => x.CreatedBy).IsModified   = false;
                                db.Entry(carrierToUpdate).OriginalValues["RowVersion"]            = RowVersion;
                                db.SaveChanges();
                                return(RedirectToAction("Index"));
                            }
                            catch (DbUpdateConcurrencyException ex)
                            {
                                var entry         = ex.Entries.Single();
                                var clientValues  = (Carrier)entry.Entity;
                                var databaseEntry = entry.GetDatabaseValues();
                                if (databaseEntry == null)
                                {
                                    TempData["ErrorMessage"] = "Unable to save changes. The record was deleted";
                                }
                                else
                                {
                                    TempData["ErrorMessage"] = "Unable to save changes. The record was edited by " + UpdatedUser + ". Select Updated Record.";
                                }
                            }
                        }
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception e)
                {
                    TempData["CustomError"] = "Carrier Name is not Unique";
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            return(View(carrier));
        }
Exemplo n.º 23
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(AccessCard accessCard, byte[] RowVersion)
        {
            string[] fieldsToBind = new string[] { "CardID", "BayID", "Active", "IsAssigned", "LastActive", "ModifiedDate", "Remarks", "CreatedDate", "CardKey" };
            if (ModelState.IsValid)
            {
                try
                {
                    if (accessCard.CardID.Equals(0))
                    {
                        accessCard.ModifiedDate = accessCard.LastActive = accessCard.CreatedDate = DateTime.Now;
                        accessCard.CreatedBy    = accessCard.ModifiedBy = User.Identity.Name;
                        int maxId = 0;
                        if (db.AccessCards.Count() > 0)
                        {
                            maxId = db.AccessCards.Max(x => x.CardID);
                        }
                        accessCard.CardID = (maxId > 0) ? (maxId + 1) : 1;
                        db.AccessCards.Add(accessCard);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        var accessCardToUpdate = db.AccessCards.Find(accessCard.CardID);
                        if (accessCardToUpdate == null)
                        {
                            AccessCard accessCardDeleted = new AccessCard();
                            TryUpdateModel(accessCardDeleted, fieldsToBind);
                            ModelState.AddModelError(string.Empty, "Unable to save changes. The Access Card was deleted by another user.");
                            return(RedirectToAction("Index"));
                        }
                        if (TryUpdateModel(accessCardToUpdate, fieldsToBind))
                        {
                            string UpdatedUser = string.Empty;
                            try
                            {
                                UpdatedUser = accessCardToUpdate.ModifiedBy;

                                accessCardToUpdate.ModifiedDate = DateTime.Now;
                                accessCardToUpdate.ModifiedBy   = User.Identity.Name;
                                db.AccessCards.Attach(accessCardToUpdate);
                                db.Entry(accessCardToUpdate).Property(x => x.BayID).IsModified        = true;
                                db.Entry(accessCardToUpdate).Property(x => x.Remarks).IsModified      = true;
                                db.Entry(accessCardToUpdate).Property(x => x.Active).IsModified       = true;
                                db.Entry(accessCardToUpdate).Property(x => x.IsAssigned).IsModified   = true;
                                db.Entry(accessCardToUpdate).Property(x => x.ModifiedDate).IsModified = true;
                                db.Entry(accessCardToUpdate).Property(x => x.ModifiedBy).IsModified   = true;


                                db.Entry <AccessCard>(accessCardToUpdate).State           = EntityState.Modified;
                                db.Entry(accessCardToUpdate).OriginalValues["RowVersion"] = RowVersion;
                                db.SaveChanges();
                                return(RedirectToAction("Index"));
                            }
                            catch (DbUpdateConcurrencyException ex)
                            {
                                var entry         = ex.Entries.Single();
                                var clientValues  = (AccessCard)entry.Entity;
                                var databaseEntry = entry.GetDatabaseValues();
                                if (databaseEntry == null)
                                {
                                    TempData["ErrorMessage"] = "Unable to save changes. The record was deleted";
                                }
                                else
                                {
                                    TempData["ErrorMessage"] = "Unable to save changes. The record was edited by " + UpdatedUser + ". Select Updated Record.";
                                }
                            }
                        }
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception ex)
                {
                    TempData["CustomError"] = "Card ID is not Unique";
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.BayID = new SelectList(db.Bays, "BayID", "Remarks", accessCard.BayID);
            return(View("Index", accessCard));
        }
Exemplo n.º 24
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "ID,AccessCardID,DeletedFlag,ShipmentStatusID,OrderID,BayID,BayName,CustomerName,VehicleCode,DriverName,DriverCNIC,CarrierName,ShipmentDate,ProductID")] Shipment shipment, FormCollection formCollection)
        {
            #region shipment compartment
            int compCountTempDataUpdate = Convert.ToInt32(TempData["CompCountUpdate"].ToString());
            if (compCountTempDataUpdate != 0)
            {
                for (int i = 0; i < compCountTempDataUpdate; i++)
                {
                    int compID = Convert.ToInt32(formCollection["compId" + i]);
                    ShipmentCompartment shipmentComp = db.ShipmentCompartments.AsNoTracking().Where(x => x.ID == compID).FirstOrDefault <ShipmentCompartment>();
                    //shipmentComp.ID = Convert.ToInt32(formCollection["compId" + i]);
                    shipmentComp.OrderedQuantity = Convert.ToInt32(formCollection["Order.OrderQty"]);
                    int compActualQty;
                    if (Int32.TryParse(formCollection["compPlannedQty" + i], out compActualQty))
                    {
                        shipmentComp.ActualBCUQuantity = compActualQty;
                    }
                    else
                    {
                        shipmentComp.ActualBCUQuantity = null;
                    }

                    //shipmentComp.AccessCardKey = shipment.AccessCardID.ToString();
                    //shipmentComp.BayID = Convert.ToInt32(shipment.BayID);
                    shipmentComp.Product    = shipment.ProductID.ToString();
                    shipmentComp.ShipmentID = shipment.ID;
                    //shipmentComp.CreatedDate = DateTime.Now;
                    shipmentComp.ModifiedDate    = DateTime.Now;
                    shipmentComp.ModifiedBy      = User.Identity.Name;
                    shipmentComp.CompartmentCode = Convert.ToInt32(formCollection["compCode" + i]);
                    shipmentComp.Capacity        = Convert.ToInt32(formCollection["compCapacity" + i]);
                    db.ShipmentCompartments.Attach(shipmentComp);
                    db.Entry(shipmentComp).Property(x => x.OrderedQuantity).IsModified   = true;
                    db.Entry(shipmentComp).Property(x => x.ActualBCUQuantity).IsModified = true;
                    db.Entry(shipmentComp).Property(x => x.Product).IsModified           = true;
                    db.Entry(shipmentComp).Property(x => x.ShipmentID).IsModified        = true;
                    db.Entry(shipmentComp).Property(x => x.ModifiedDate).IsModified      = true;
                    db.Entry(shipmentComp).Property(x => x.ModifiedBy).IsModified        = true;
                    db.Entry(shipmentComp).Property(x => x.CompartmentCode).IsModified   = true;
                    db.Entry(shipmentComp).Property(x => x.Capacity).IsModified          = true;
                    db.Entry(shipmentComp).State = EntityState.Modified;
                    db.SaveChanges();
                    //db.Entry(shipmentComp).State = EntityState.Detached;
                }
            }
            else
            {
                int compCountTempDataNew = Convert.ToInt32(TempData["CompCountNew"].ToString());
                for (int i = 0; i < compCountTempDataNew; i++)
                {
                    try
                    {
                        //shipment.ShipmentStatusID = 2; // shipment status id is set to queued.
                        ShipmentCompartment shipmentComp = new ShipmentCompartment();
                        shipmentComp.OrderedQuantity = Convert.ToInt32(formCollection["Order.OrderQty"]);
                        int compPlannedQty;
                        if (Int32.TryParse(formCollection["compPlannedQty" + i], out compPlannedQty))
                        {
                            shipmentComp.PlannedQuantity = compPlannedQty;
                        }
                        else
                        {
                            shipmentComp.PlannedQuantity = null;
                        }

                        shipmentComp.AccessCardKey   = shipment.AccessCardID.ToString();
                        shipmentComp.BayID           = Convert.ToInt32(shipment.BayID);
                        shipmentComp.Product         = shipment.ProductID.ToString();
                        shipmentComp.ShipmentID      = shipment.ID;
                        shipmentComp.CreatedDate     = DateTime.Now;
                        shipmentComp.CreatedBy       = User.Identity.Name;
                        shipmentComp.ModifiedDate    = DateTime.Now;
                        shipmentComp.ModifiedBy      = User.Identity.Name;
                        shipmentComp.CompartmentCode = Convert.ToInt32(formCollection["compCode" + i]);
                        shipmentComp.Capacity        = Convert.ToInt32(formCollection["compCapacity" + i]);
                        db.ShipmentCompartments.Add(shipmentComp);
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        e.ToString();
                    }
                }
            }
            #endregion
            if (shipment.ShipmentStatusID == 5)
            {
                Order odr = db.Orders.Where(x => x.OrderID == shipment.OrderID).FirstOrDefault <Order>();
                odr.OrderStatusID   = 3;
                odr.OrderDeliveryDT = DateTime.Now;
                odr.ModifiedDate    = DateTime.Now;
                odr.ModifiedBy      = User.Identity.Name;
                db.Orders.Attach(odr);
                db.Entry(odr).Property(x => x.ModifiedDate).IsModified    = true;
                db.Entry(odr).Property(x => x.ModifiedBy).IsModified      = true;
                db.Entry(odr).Property(x => x.OrderStatusID).IsModified   = true;
                db.Entry(odr).Property(x => x.OrderDeliveryDT).IsModified = true;
                db.SaveChanges();

                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                AccessCard accessCard = db.AccessCards.Where(x => x.CardID == shipment.AccessCardID).FirstOrDefault <AccessCard>();
                accessCard.CardID       = (int)shipment.AccessCardID;
                accessCard.IsAssigned   = false;
                accessCard.ModifiedDate = DateTime.Now;
                accessCard.ModifiedBy   = User.Identity.Name;
                db.AccessCards.Attach(accessCard);
                db.Entry(accessCard).Property(x => x.ModifiedDate).IsModified = true;
                db.Entry(accessCard).Property(x => x.ModifiedBy).IsModified   = true;
                db.Entry(accessCard).Property(x => x.IsAssigned).IsModified   = true;
                db.Entry(accessCard).State = EntityState.Modified; //commneted by ahad for performance
                db.SaveChanges();
                //db.Entry(accessCard).State = EntityState.Detached;
            }
            if (ModelState.IsValid)
            {
                shipment.ModifiedDate = DateTime.Now;
                shipment.ModifiedBy   = User.Identity.Name;
                db.Shipments.Attach(shipment);
                db.Entry(shipment).Property(x => x.ModifiedDate).IsModified     = true;
                db.Entry(shipment).Property(x => x.ModifiedBy).IsModified       = true;
                db.Entry(shipment).Property(x => x.ShipmentStatusID).IsModified = true;
                //db.Entry(shipment).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AccessCardID     = new SelectList(db.AccessCards, "CardID", "Remarks", shipment.AccessCardID);
            ViewBag.BayID            = new SelectList(db.Bays, "BayID", "Remarks", shipment.BayID);
            ViewBag.OrderID          = new SelectList(db.Orders, "OrderID", "OrderCode", shipment.OrderID);
            ViewBag.ShipmentStatusID = new SelectList(db.ShipmentStatus, "ID", "Status", shipment.ShipmentStatusID);
            ViewBag.ID = new SelectList(db.WeighBridges, "ShipmentID", "Status", shipment.ID);
            return(View(shipment));
        }
Exemplo n.º 25
0
        // [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "OrderID,OrderDate,OrderQty,RemainQty,CustomerID,ProductID,OrderCode,DeletedFlag,CarrierID,VehicleID,OrderStatusID,OrderDeliveryDT,RowVersion")] Order order, FormCollection formCollection, byte[] RowVersion)
        {
            string[] fieldsToBind = { "OrderID", "OrderDate", "OrderQty", "RemainQty", "CustomerID", "ProductID", "OrderCode", "DeletedFlag", "CarrierID", "VehicleID", "OrderStatusID", "OrderDeliveryDT", "CustomerName", "CarrierName", "VehicleCode", "DriverName", "DriverCNIC", "ProductID" };

            try
            {
                if (ModelState.IsValid)
                {
                    if (order.OrderID.Equals(0))
                    {
                        var shipment = new Shipment()
                        {
                            ProductID        = order.ProductID,
                            IsManual         = false,
                            CreatedDate      = DateTime.Now,
                            CreatedBy        = User.Identity.Name,
                            ModifiedDate     = DateTime.Now,
                            ModifiedBy       = User.Identity.Name,
                            ShipmentStatusID = 1,
                            OrderID          = order.OrderID,
                            CustomerName     = formCollection["Customer.CustomerName"],
                            CarrierName      = formCollection["Carrier.CarrierName"],
                            VehicleCode      = formCollection["Vehicle.VehicleCode"],
                            DriverName       = formCollection["Vehicle.Driver.DriverName"],
                            DriverCNIC       = formCollection["Vehicle.Driver.CNIC"]
                        };
                        ///////////////////////////////////////////////////////////////
                        order.CreatedDate  = DateTime.Now;
                        order.CreatedBy    = User.Identity.Name;
                        order.ModifiedDate = DateTime.Now;
                        order.ModifiedBy   = User.Identity.Name;
                        db.Orders.Add(order);
                        //////////////////////////////////////////////////////////////
                        db.Shipments.Add(shipment);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        string UpdatedUser = string.Empty;
                        try
                        {
                            Shipment ship = db.Shipments.Where(x => x.OrderID == order.OrderID).FirstOrDefault <Shipment>();
                            //TryUpdateModel(ship, fieldsToBind);//
                            UpdatedUser       = ship.ModifiedBy;//
                            ship.ModifiedDate = DateTime.Now;
                            ship.ModifiedBy   = User.Identity.Name;
                            ship.CustomerName = formCollection["Customer.CustomerName"];
                            ship.CarrierName  = formCollection["Carrier.CarrierName"];
                            ship.VehicleCode  = formCollection["Vehicle.VehicleCode"];
                            ship.DriverName   = formCollection["Vehicle.Driver.DriverName"];
                            ship.DriverCNIC   = formCollection["Vehicle.Driver.CNIC"];
                            ship.ProductID    = order.ProductID;
                            db.Shipments.Attach(ship);
                            db.Entry(ship).Property(x => x.ModifiedDate).IsModified = true;
                            db.Entry(ship).Property(x => x.ModifiedBy).IsModified   = true;
                            db.Entry(ship).Property(x => x.CustomerName).IsModified = true;
                            db.Entry(ship).Property(x => x.CarrierName).IsModified  = true;
                            db.Entry(ship).Property(x => x.VehicleCode).IsModified  = true;
                            db.Entry(ship).Property(x => x.DriverName).IsModified   = true;
                            db.Entry(ship).Property(x => x.DriverCNIC).IsModified   = true;
                            db.Entry(ship).Property(x => x.ProductID).IsModified    = true;
                            db.Entry(ship).State = EntityState.Modified;
                            /////////////////////////////////////////////////////////////////////////////////////
                            order.ModifiedDate    = DateTime.Now;
                            order.ModifiedBy      = User.Identity.Name;
                            db.Entry(order).State = EntityState.Modified;
                            db.Entry(order).Property(x => x.CreatedDate).IsModified = false;
                            db.Entry(order).Property(x => x.CreatedBy).IsModified   = false;

                            ////////////////////////////////////////////////////////////////////////////////////

                            //db.Entry(order).OriginalValues["RowVersion"] = RowVersion;
                            //Shipment ship1 = db.Shipments.Where(x => x.OrderID == order.OrderID).FirstOrDefault<Shipment>();
                            //Order order1 = db.Orders.Where(x => x.OrderID == order.OrderID).FirstOrDefault<Order>();//
                            db.Entry(order).OriginalValues["RowVersion"] = RowVersion;//


                            ///////////////

                            db.SaveChanges();

                            return(RedirectToAction("Index"));
                        }
                        catch (DbUpdateConcurrencyException ex)
                        {
                            var entry         = ex.Entries.Single();
                            var clientValues  = (Order)entry.Entity;
                            var databaseEntry = entry.GetDatabaseValues();
                            if (databaseEntry == null)
                            {
                                TempData["ErrorMessage"] = "Unable to save changes. The record was deleted";
                            }
                            else
                            {
                                TempData["ErrorMessage"] = "Unable to save changes. The record was edited by " + UpdatedUser + ". Select Updated Record.";
                            }
                        }
                    }
                }
                else
                {
                    var errors = ModelState.Values.SelectMany(v => v.Errors);
                }
            }
            catch
            {
                TempData["CustomError"] = "Order Code is not Unique";
                return(RedirectToAction("Index"));
            }

            ViewBag.CarrierID     = new SelectList(db.Carriers, "CarrierID", "CarrierName", order.CarrierID);
            ViewBag.CustomerID    = new SelectList(db.Customers, "CustomerID", "CustomerName", order.CustomerID);
            ViewBag.ProductID     = new SelectList(db.Products, "ProductID", "ProductName", order.ProductID);
            ViewBag.OrderStatusID = new SelectList(db.OrderStatus, "ID", "Status", order.OrderStatusID);
            ViewBag.VehicleID     = new SelectList(db.Vehicles, "VehicleID", "VehicleCode", order.VehicleID);
            return(RedirectToAction("Index"));
            //return View(order);
        }