public static VendorLocationModel GetVendorLocation(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        var tblVendorLocation = rc.TblVendorLocations.FirstOrDefault(v => v.VendorID == id);

                        if (tblVendorLocation != null)
                        {
                            VendorLocationModel vendorLocation = new VendorLocationModel
                            {
                                VendorID  = tblVendorLocation.VendorID,
                                LocationX = tblVendorLocation.LocationX,
                                LocationY = tblVendorLocation.LocationY,
                                Date      = (DateTime)tblVendorLocation.Datetime
                            };
                            return(vendorLocation);
                        }
                        throw new Exception("Vendor location cannot be found");
                    }
                }
                else
                {
                    throw new Exception("ID cannot be 0");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Seed()
        {
            VendorLocationModel vendorLocation = new VendorLocationModel
            {
                VendorID  = 1,
                LocationX = 100,
                LocationY = 200,
                Date      = new DateTime(1950, 12, 31),
            };

            return(Insert(vendorLocation));
        }
Beispiel #3
0
        public void Update()
        {
            VendorLocationModel vendorLocation = new VendorLocationModel
            {
                VendorID  = 2,
                LocationX = 111,
                LocationY = 222,
                Date      = new DateTime(1950, 12, 31)
            };

            VendorLocationManager.Update(vendorLocation);
            VendorLocationModel newVendorLocation = VendorLocationManager.GetVendorLocation(2);

            Assert.AreEqual(vendorLocation.VendorID, newVendorLocation.VendorID);
        }
 public static bool Insert(VendorLocationModel vendorLocation)
 {
     try
     {
         using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
         {
             PL.TblVendorLocation newRow = new TblVendorLocation()
             {
                 VendorID  = rc.TblVendorLocations.Any() ? rc.TblVendorLocations.Max(v => v.VendorID) + 1 : 1,
                 LocationX = vendorLocation.LocationX,
                 LocationY = vendorLocation.LocationY,
                 Datetime  = vendorLocation.Date
             };
             rc.TblVendorLocations.Add(newRow);
             rc.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public static bool Update(VendorLocationModel vendorLocation)
        {
            try
            {
                if (vendorLocation.VendorID != 0)
                {
                    using (RoundTheCornerEntities rc = new RoundTheCornerEntities())
                    {
                        TblVendorLocation tblVendorLocation = rc.TblVendorLocations.FirstOrDefault(v => v.VendorID == vendorLocation.VendorID);

                        if (tblVendorLocation != null)
                        {
                            tblVendorLocation.VendorID  = vendorLocation.VendorID;
                            tblVendorLocation.LocationX = vendorLocation.LocationX;
                            tblVendorLocation.LocationY = vendorLocation.LocationY;
                            tblVendorLocation.Datetime  = vendorLocation.Date;

                            rc.SaveChanges();
                            return(true);
                        }
                        else
                        {
                            throw new Exception("Vendor was not found");
                        }
                    }
                }
                else
                {
                    throw new Exception("Must have a valid id");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }