Beispiel #1
0
        public EditResponseModel<MauTronModel> UpdateMauTron(EditMauTronModel model)
        {
            try
            {
                //Get mautron
                var mauTron = DataContext.MauTrons.SingleOrDefault(m => m.Id == model.Id);
                if(mauTron == null)
                    return new EditResponseModel<MauTronModel>{Result = false, Message = "Không tìm thấy mẫu trộn!"};

                mauTron.GhiChu = model.GhiChu;
                mauTron.MaMauTron = model.MaMauTron;
                mauTron.SoPhuy = model.SoPhuy;
                mauTron.NgayTron = model.NgayTron;
                mauTron.NgayCapNhat = DateTime.Now;
                mauTron.NguoiCapNhat = model.NguoiCapNhat;

                DataContext.ChiTietMauTrons.RemoveRange(DataContext.ChiTietMauTrons.Where(m=>m.IdMauTron ==model.Id));
                DataContext.ChiTietMauTrons.AddRange(model.MauCons.Select(item => new ChiTietMauTron()
                {
                    GhiChu = item.GhiChu, SoPhuy = item.SoPhuy, Id = item.Id, IdMauCon = item.IdMauCon, IdMauTron = model.Id, LoaiMau = item.LoaiMau
                }));

                var result = DataContext.SaveChanges();
                return new EditResponseModel<MauTronModel>{Result = result > 0};

            }
            catch (Exception exception)
            {
                return new EditResponseModel<MauTronModel>{Result = false, Message = exception.ToString()};
            }
        }
Beispiel #2
0
        public EditResponseModel<MauTronModel> InsertMauTron(EditMauTronModel model)
        {
            try
            {
                var mautron = new MauTron
                {
                    GhiChu = model.GhiChu,
                    Id = Guid.NewGuid(),
                    MaMauTron = model.MaMauTron,
                    NgayTron = model.NgayTron,
                    NguoiTao = model.NguoiTao,
                    NgayTao = DateTime.Now,
                    SoPhuy = model.SoPhuy
                };

                DataContext.MauTrons.Add(mautron);

                foreach (var chitiet in model.MauCons.Select(item => new ChiTietMauTron()
                {
                    Id = Guid.NewGuid(),
                    GhiChu = item.GhiChu,
                    LoaiMau = item.LoaiMau,
                    IdMauTron = mautron.Id,
                    IdMauCon = item.IdMauCon,
                    SoPhuy = item.SoPhuy
                }))
                {
                    DataContext.ChiTietMauTrons.Add(chitiet);
                }

                var result = DataContext.SaveChanges();

                return new EditResponseModel<MauTronModel>{Result = result > 0};

            }
            catch (Exception exception)
            {
                return new EditResponseModel<MauTronModel>{Message = exception.ToString(), Result = false};
            }
        }