Beispiel #1
0
        public static void Update(term new_term, long term_id)
        {
            var term = SelectById(term_id);

            new_term.id = term_id;
            if (term != null)
            {
                term.hall_id         = new_term.hall_id;
                term.rental_date     = new_term.rental_date;
                term.rent_time_start = new_term.rent_time_start;
                term.rent_time_end   = new_term.rent_time_end;
                term.note            = new_term.note;
                foreach (item_list item in term.items.ToList())
                {
                    if (!new_term.items.Any(i => i.item_id == item.item_id))
                    {
                        context.item_list.Remove(item);
                    }
                }
                foreach (item_list item in new_term.items)
                {
                    var new_item = term.items.FirstOrDefault(i => i.item_id == item.item_id);
                    if (new_item != null && item.quantity != new_item.quantity)
                    {
                        item_list.Update(new_item, item.term_id);
                    }
                    else if (new_item == null)
                    {
                        item.term_id = term.id;
                        item_list.Insert(item);
                    }
                }
                context.SaveChanges();
            }
        }
Beispiel #2
0
        public static bool CheckItem(int item_id, term term)
        {
            var items = context.item_list.Where(i => i.item_id == item_id).ToList();

            foreach (item_list item in items)
            {
                var check_term = term.SelectById(term.id);
                if (check_term != null && check_term.rental_date.CompareTo(term.rental_date) == 0 &&
                    check_term.rent_time_end.CompareTo(term.rent_time_start) == 1)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #3
0
 public static void Insert(term term)
 {
     context.terms.Add(term);
     context.SaveChanges();
 }