Exemple #1
0
 public PhuKien_DTO GetById(string tbvt_ma)
 {
     return(PhuKienService.PhuKien_ById(tbvt_ma));
 }
        public List <dynamic> Update([FromBody] ThietBiVatTu input)
        {
            try
            {
                ThietBiVatTu_Dto modeldb = new ThietBiVatTu_Dto
                {
                    TBVT_ID                     = input.TBVT_ID.Value,
                    TBVT_MA_TBVT                = input.TBVT_MA_TBVT,
                    TBVT_TEN                    = input.TBVT_TEN,
                    TBVT_SERIAL                 = input.TBVT_SERIAL,
                    TBVT_LOAI                   = input.TBVT_LOAI,
                    TBVT_NGAY_MUA               = input.TBVT_NGAY_MUA,
                    TBVT_DVT                    = input.TBVT_DVT,
                    TBVT_NHAP_THEO_LO           = input.TBVT_NHAP_THEO_LO,
                    TBVT_SL_THEO_LO             = input.TBVT_SL_THEO_LO,
                    TBVT_HANG_SX                = input.TBVT_HANG_SX,
                    TBVT_NAM_SX                 = input.TBVT_NAM_SX,
                    TBVT_NGAY_TINH_BAO_HANH     = input.TBVT_NGAY_TINH_BAO_HANH,
                    TBVT_NGAY_KET_THUC_BAO_HANH = input.TBVT_NGAY_KET_THUC_BAO_HANH,
                    TBVT_NHA_CUNG_CAP           = input.TBVT_NHA_CUNG_CAP,
                    TBVT_TINH_TRANG_THIET_BI    = input.TBVT_TINH_TRANG_THIET_BI,
                    TBVT_GHI_CHU_TINH_TRANG     = input.TBVT_GHI_CHU_TINH_TRANG,
                    TBVT_CAN_BAO_DUONG          = input.TBVT_CAN_BAO_DUONG,
                    TBVT_CHU_KY_BAO_DUONG       = input.TBVT_CHU_KY_BAO_DUONG,
                    TBVT_NOI_DUNG_BAO_DUONG     = input.TBVT_NOI_DUNG_BAO_DUONG,
                    TBVT_TI_LE_HAO_MON          = input.TBVT_TI_LE_HAO_MON,
                    TBVT_TINH_TRANG_TBTBVT      = input.TBVT_TINH_TRANG_TBTBVT
                };
                Console.WriteLine("update {0} processing", input.TBVT_MA_TBVT);

                var result = ChiTietThietBiVatTuService.CTTBVT_Update(modeldb);

                var updateResult = result.FirstOrDefault();

                if (updateResult.Result < 0)
                {
                    Console.WriteLine("update error: {0}", updateResult.ErrorDesc);
                }


                if (input.TBVT_PhuKien == null)
                {
                    Console.WriteLine("no PhuKien updated", input.TBVT_MA_TBVT);

                    return(result);
                }

                foreach (var phukien in input.TBVT_PhuKien)
                {
                    PhuKien_DTO phukienDto = PhuKienService.PhuKien_ById(phukien.PHU_KIEN_MA_PK);
                    if (phukien != null)
                    {
                        Console.WriteLine("updating phukien {0} ", phukien.PHU_KIEN_ID);

                        phukienDto.PHU_KIEN_DVT      = phukien.PHU_KIEN_DVT;
                        phukienDto.PHU_KIEN_GHI_CHU  = phukien.PHU_KIEN_GHI_CHU;
                        phukienDto.PHU_KIEN_SO_LUONG = phukien.PHU_KIEN_SO_LUONG;
                        phukienDto.PHU_KIEN_TEN      = phukien.PHU_KIEN_TEN;

                        var phukienResult = PhuKienService.PhuKien_Update(phukienDto).FirstOrDefault();

                        if (phukienResult.Result < 0)
                        {
                            Console.WriteLine("update failed phukien {0} ", phukien.PHU_KIEN_ID);
                            Console.WriteLine(phukienResult.ErrorDesc);
                        }
                        else
                        {
                            Console.WriteLine("updated phukien {0} ", phukien.PHU_KIEN_ID);
                        }
                    }
                    else
                    {
                        PhuKien_DTO vt_phukien = phukien;
                        vt_phukien.PHU_KIEN_TBVT_ID = updateResult.TBVTID;
                        var phukienResult = PhuKienService.PhuKien_Insert(vt_phukien).FirstOrDefault();

                        if (phukienResult.Result < 0)
                        {
                            Console.WriteLine("insert failed phukien {0} ", phukien.PHU_KIEN_ID);
                            Console.WriteLine(phukienResult.ErrorDesc);
                        }
                        else
                        {
                            Console.WriteLine("inserted phukien {0} ", phukien.PHU_KIEN_ID);
                        }
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);

                return(new List <dynamic>
                {
                    new { Result = -1, ErrorDesc = "Có lỗi phía hệ thông, vui lòng báo lên trị viên" }
                });
            }
        }