Exemple #1
0
        public IEnumerable <OrderDetailRecord> QueryByParent(int parentId)
        {
            var query = _thisDAL.QueryByParent(parentId);

            return(query);
        }
Exemple #2
0
        public void Edit(ViewModel.Order.EditForm form)
        {
            var orderDate    = DateTime.Now;
            var deliveryDate = DateTime.Now;

            DateTime.TryParse(form.OrderDate, out orderDate);
            DateTime.TryParse(form.DeliveryDate, out deliveryDate);
            var fdetails = new List <OrderDetailRecord>();

            var model   = _thisDAL.Query(form.Id);
            var details = _orderDetailDal.QueryByParent(form.Id);

            model.OrderNo      = form.OrderNo;
            model.Supplier     = form.Supplier;
            model.LinkPerson   = form.LinkPerson;
            model.Phone        = form.Phone;
            model.Tel          = form.Tel;
            model.Fax          = form.Fax;
            model.DeliveryDate = deliveryDate;
            model.ModifyTime   = DateTime.Now;
            model.Address      = form.Address;
            model.Remark       = form.Remark;
            model.Contract     = form.Contract;

            foreach (var det in form.Details)
            {
                fdetails.Add(new OrderDetailRecord
                {
                    Id        = det.Id,
                    Order_Id  = model.Id,
                    SortIndex = det.SortIndex,
                    Name      = det.Name,
                    Size      = det.Size,
                    Unit      = det.Unit,
                    Total     = det.Total,
                    Output    = det.Output,
                    Remark    = det.Remark
                });
            }
            var equal       = new OrderDetailEqualityBy();
            var addDetails  = fdetails.Where(w => w.Id == -1).ToList();
            var editDetails = fdetails.Intersect(details, equal).ToList();
            var delDetails  = details.Except(fdetails, equal).ToList();

            try
            {
                _thisDAL.Update(model);
                foreach (var del in delDetails)
                {
                    _orderDetailDal.Delete(del);
                }
                foreach (var edit in editDetails)
                {
                    _orderDetailDal.Update(edit);
                }
                foreach (var add in addDetails)
                {
                    _orderDetailDal.Add(add);
                }
            }
            catch (Exception e)
            {
                _thisDAL.AbortTransaction();
                throw e;
            }
        }