Пример #1
0
        public bool Edit(MeasurementDetailRecord newInstance)
        {
            var db = new MaterialMeasurementEntities();

            try
            {
                var currentInstance = db.MeasurementDetailRecords.FirstOrDefault(m => m.ID == newInstance.ID);
                if (currentInstance == null)
                {
                    return(false);
                }
                currentInstance.MeasurementRecordID = newInstance.MeasurementRecordID;
                currentInstance.RawMaterialID       = newInstance.RawMaterialID;
                currentInstance.Weight     = newInstance.Weight;
                currentInstance.WeightUnit = newInstance.WeightUnit;

                db.Entry(currentInstance).State = System.Data.Entity.EntityState.Modified;
                SaveChanges(db);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Пример #2
0
        public bool AddMonthReport(int month, int year, MonthReport newInstance)
        {
            var db = new MaterialMeasurementEntities();

            try
            {
                var monthReport = db.MonthReports.Where(i => i.MaterialId == newInstance.MaterialId &&
                                                        i.ParcelCode == newInstance.ParcelCode && i.ReportDate.Month == month &&
                                                        i.ReportDate.Year == year).FirstOrDefault();
                if (monthReport == null)
                {
                    db.MonthReports.Add(newInstance);
                    SaveChanges(db);
                }

                if (monthReport != null)
                {
                    monthReport.RemainQuantity  = monthReport.RemainQuantity == 0 ? newInstance.RemainQuantity : monthReport.RemainQuantity;
                    monthReport.ImportQuantity  = monthReport.ImportQuantity == 0 ? newInstance.ImportQuantity : monthReport.ImportQuantity;
                    monthReport.ExportQuantity  = monthReport.ExportQuantity == 0 ? newInstance.ExportQuantity : monthReport.ExportQuantity;
                    db.Entry(monthReport).State = System.Data.Entity.EntityState.Modified;
                    SaveChanges(db);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            return(true);
        }
Пример #3
0
        public bool Edit(Material newInstance)
        {
            var db = new MaterialMeasurementEntities();

            try
            {
                var currentInstance = db.Materials.FirstOrDefault(m => m.ID == newInstance.ID);
                if (currentInstance == null)
                {
                    return(false);
                }
                currentInstance.Name      = newInstance.Name;
                currentInstance.PatId     = newInstance.PatId;
                currentInstance.Revision  = newInstance.Revision;
                currentInstance.Code      = newInstance.Code;
                currentInstance.IsDeleted = newInstance.IsDeleted;
                currentInstance.TypeID    = newInstance.TypeID;

                db.Entry(currentInstance).State = System.Data.Entity.EntityState.Modified;
                SaveChanges(db);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
        public bool Edit(ImportedInventory newInstance)
        {
            var db = new MaterialMeasurementEntities();

            try
            {
                var currentInstance = db.ImportedInventories.FirstOrDefault(m => m.ID == newInstance.ID);
                if (currentInstance == null)
                {
                    return(false);
                }
                currentInstance.MaterialID = newInstance.MaterialID;
                currentInstance.ParcelCode = newInstance.ParcelCode;
                currentInstance.ImportDate = newInstance.ImportDate;
                currentInstance.Quantity   = newInstance.Quantity;
                currentInstance.WeightUnit = newInstance.WeightUnit;

                db.Entry(currentInstance).State = System.Data.Entity.EntityState.Modified;
                SaveChanges(db);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Пример #5
0
        public bool Delete(long Id)
        {
            var db = new MaterialMeasurementEntities();

            try
            {
                var currentInstance = db.MeasurementDetailRecords.FirstOrDefault(m => m.ID == Id);
                if (currentInstance == null)
                {
                    return(false);
                }
                db.Entry(currentInstance).State = System.Data.Entity.EntityState.Deleted;
                SaveChanges(db);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Пример #6
0
        public bool Delete(string username)
        {
            var db = new MaterialMeasurementEntities();

            try
            {
                var currentInstance = db.Users.FirstOrDefault(u => u.Username.Equals(username));
                if (currentInstance == null)
                {
                    return(false);
                }
                db.Entry(currentInstance).State = System.Data.Entity.EntityState.Deleted;
                SaveChanges(db);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Пример #7
0
        public bool Edit(User newInstance)
        {
            var db = new MaterialMeasurementEntities();

            try
            {
                var currentInstance = db.Users.FirstOrDefault(u => u.Username.Equals(newInstance.Username));
                if (currentInstance == null)
                {
                    return(false);
                }
                currentInstance.Password = newInstance.Password;

                db.Entry(currentInstance).State = System.Data.Entity.EntityState.Modified;
                SaveChanges(db);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }