예제 #1
0
        public static string Add(EventHistoryDTO eventHistory)
        {
            using (WarehouseSystemContext db = new WarehouseSystemContext())
            {
                string       error           = null;
                EventHistory newEventHistory = new EventHistory();
                newEventHistory.Id        = eventHistory.Id;
                newEventHistory.EventId   = eventHistory.EventId;
                newEventHistory.StartDate = eventHistory.StartDate;

                var context = new ValidationContext(newEventHistory, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(newEventHistory, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.EventHistory.Add(newEventHistory);
                    db.SaveChanges();
                }
                return(error);
            }
        }
예제 #2
0
        public static string Edit(EventHistoryDTO eventHistory)
        {
            using (WarehouseSystemContext db = new WarehouseSystemContext())
            {
                string error = null;

                var toModify = db.EventHistory.Where(x => x.Id == eventHistory.Id).FirstOrDefault();

                toModify.Id        = eventHistory.Id;
                toModify.EventId   = eventHistory.EventId;
                toModify.StartDate = eventHistory.StartDate;

                var context = new ValidationContext(toModify, null, null);
                var result  = new List <ValidationResult>();
                Validator.TryValidateObject(toModify, context, result, true);

                foreach (var x in result)
                {
                    error = error + x.ErrorMessage + "\n";
                }

                if (error == null)
                {
                    db.SaveChanges();
                }
                return(error);
            }
        }
예제 #3
0
        public static void Delete(EventHistoryDTO eventHistory)
        {
            using (WarehouseSystemContext db = new WarehouseSystemContext())
            {
                var toDelete = db.EventHistory.Where(x => x.Id == eventHistory.Id).FirstOrDefault();
                toDelete.IsDisabled = true;

                db.SaveChanges();
            }
        }