Exemplo n.º 1
0
        public MappingDataDTO GetMappingData(string mp_id)
        {
            MappingDataDTO objModel = new MappingDataDTO();

            using (var _db = new LabDataContext())
            {
                using (var trans = _db.Database.BeginTransaction())
                {
                    try
                    {
                        objModel = _db.MappingDataDTOs.FromSqlRaw <MappingDataDTO>("sp_GET_TRMappingByID {0}", mp_id).AsEnumerable().FirstOrDefault();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        // TODO: Handle failure
                        trans.Rollback();
                    }
                    finally
                    {
                        trans.Dispose();
                    }
                }
            }
            return(objModel);
        }
Exemplo n.º 2
0
        public MappingDataDTO GetMappingDataActiveWithModel(MappingDataDTO model)
        {
            log.MethodStart();
            MappingDataDTO objModel = new MappingDataDTO();

            using (var trans = _db.Database.BeginTransaction())
            {
                try
                {
                    var objDataList = _db.TRMappings.FromSqlRaw <TRMapping>("sp_GET_TRMapping_Approve_Active {0} ,{1} ,{2} ,{3}", model.mp_hos_code, model.mp_lab, model.mp_program, model.mp_filetype).ToList();

                    var objListMapping = _mapper.Map <List <MappingDataDTO> >(objDataList);

                    if (objListMapping.Count > 0)
                    {
                        objModel = objListMapping.FirstOrDefault();
                    }
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    // TODO: Handle failure
                    trans.Rollback();
                }
                finally
                {
                    trans.Dispose();
                }
            }


            log.MethodFinish();

            return(objModel);
        }
Exemplo n.º 3
0
        public async Task <MappingDataDTO> SaveMappingDataAsync(MappingDataDTO model)
        {
            if (model.mp_id.Equals(Guid.Empty))
            {
                model.mp_id     = Guid.NewGuid();
                model.mp_status = 'N';
                if (model.mp_version == 0)
                {
                    model.mp_version = 1;
                }
                model.mp_flagdelete = false;
            }

            if (model.mp_status.Equals('A'))
            {
                model.mp_status = 'A';
            }


            model.mp_updatedate = DateTime.Now;

            var mapping = await _apiHelper.PostDataAsync <MappingDataDTO>("mapping_api/Post_SaveMappingData", model);

            return(mapping);
        }
Exemplo n.º 4
0
        public async Task <MappingDataDTO> GetMappingDataActiveWithModelAsync(MappingDataDTO model)
        {
            MappingDataDTO objList = new MappingDataDTO();

            objList = await _apiHelper.GetDataByModelAsync <MappingDataDTO, MappingDataDTO>("mapping_api/Get_MappingDataActiveWithModel", model);

            return(objList);
        }
Exemplo n.º 5
0
        public async Task <MappingDataDTO> GetchkDuplicateMappingApprovedAsync(MappingDataDTO model)
        {
            MappingDataDTO objList = new MappingDataDTO();

            objList = await _apiHelper.GetDataByModelAsync <MappingDataDTO, MappingDataDTO>("mapping_api/Get_chkDuplicateMappingApproved", model);

            return(objList);
        }
Exemplo n.º 6
0
        public async Task <MappingDataDTO> GetMappingDataAsync(string mp_Id)
        {
            MappingDataDTO mapping = new MappingDataDTO();

            mapping = await _apiHelper.GetDataByIdAsync <MappingDataDTO>("mapping_api/GetMappingDataById", mp_Id);

            return(mapping);
        }
Exemplo n.º 7
0
        public MappingDataDTO chkDuplicateMappingApproved(MappingDataDTO model)
        {
            log.MethodStart();
            MappingDataDTO objModel = new MappingDataDTO();

            using (var trans = _db.Database.BeginTransaction())
            {
                try
                {
                    var objReturn1 = _db.TRMappings.OrderByDescending(x => x.mp_version).FirstOrDefault(x => x.mp_lab == model.mp_lab &&
                                                                                                        x.mp_hos_code == model.mp_hos_code &&
                                                                                                        x.mp_program == model.mp_program &&
                                                                                                        x.mp_filetype == model.mp_filetype &&
                                                                                                        x.mp_startdate > model.mp_startdate &&
                                                                                                        x.mp_status == 'A' &&
                                                                                                        x.mp_flagdelete == false);


                    if (objReturn1 != null)
                    {
                        objModel = _mapper.Map <MappingDataDTO>(objReturn1);
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    // TODO: Handle failure
                    trans.Rollback();
                }
                finally
                {
                    trans.Dispose();
                }
            }


            log.MethodFinish();

            return(objModel);
        }
        public async Task <List <LabFileUploadErrorMessageDTO> > ValidateLabFileAsync(IFileListEntry fileEntry, MappingDataDTO MappingTemplate)
        {
            var ErrorMessage = new List <LabFileUploadErrorMessageDTO>();
            int row          = 1;

            try
            {
                string path = "";
                List <ParameterDTO> objParamList = new List <ParameterDTO>();
                var searchModel = new ParameterDTO()
                {
                    prm_code_major = "UPLOAD_PATH"
                };

                objParamList = await _apiHelper.GetDataListByModelAsync <ParameterDTO, ParameterDTO>("dropdownlist_api/GetParameterList", searchModel);

                if (objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH") != null)
                {
                    path = objParamList.FirstOrDefault(x => x.prm_code_minor == "PATH").prm_value;
                }
                else
                {
                    ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                    {
                        lfu_status      = 'E',
                        lfu_Err_type    = 'E',
                        lfu_Err_no      = 1,
                        lfu_Err_Column  = "",
                        lfu_Err_Message = "ไม่พบ Config PATH กรุณาติดต่อผู้ดูแลระบบ "
                    });

                    return(ErrorMessage);
                }



                string str_CurrentDate = DateTime.Now.ToString("yyyyMMdd");

                path = Path.Combine(path, str_CurrentDate, MappingTemplate.mp_hos_code);
                bool exists = System.IO.Directory.Exists(path);

                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                path = Path.Combine(path, fileEntry.Name);

                using (FileStream file = new FileStream(path, FileMode.Create))
                {
                    try
                    {
                        await fileEntry.Data.CopyToAsync(file);
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        file.Flush();
                    }
                }


                WHONetMappingSearch searchWHONet = new WHONetMappingSearch();
                searchWHONet.wnm_mappingid = MappingTemplate.mp_id;
                searchWHONet.wnm_mst_code  = MappingTemplate.mp_mst_code;

                List <WHONetMappingListsDTO> WHONetColumn = await _apiHelper.GetDataListByModelAsync <WHONetMappingListsDTO, WHONetMappingSearch>("mapping_api/Get_WHONetMappingListByModel", searchWHONet);

                var WHONetColumnMandatory = WHONetColumn.Where(x => x.wnm_mandatory == true);
                #region ReadExcel
                if (Path.GetExtension(fileEntry.Name) == ".xls" || Path.GetExtension(fileEntry.Name) == ".xlsx")
                {
                    ExcelDataSetConfiguration option = new ExcelDataSetConfiguration();

                    using (var stream = File.Open(path, FileMode.Open, FileAccess.Read))
                    {
                        using (var reader = ExcelReaderFactory.CreateReader(stream))
                        {
                            DataSet result = new DataSet();

                            //First row is header
                            if (MappingTemplate.mp_firstlineisheader == true)
                            {
                                result = reader.AsDataSet(new ExcelDataSetConfiguration()
                                {
                                    ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
                                    {
                                        UseHeaderRow = true
                                    }
                                }
                                                          );
                            }
                            else
                            {
                                result = reader.AsDataSet();
                            }

                            ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                            {
                                lfu_status      = 'I',
                                lfu_Err_type    = 'I',
                                lfu_Err_no      = 1,
                                lfu_Err_Column  = "Total",
                                lfu_Err_Message = result.Tables[0].Rows.Count.ToString()
                            });

                            foreach (WHONetMappingListsDTO item in WHONetColumnMandatory)
                            {
                                var wnm_originalfield = item.wnm_originalfield;
                                if (MappingTemplate.mp_firstlineisheader == false)
                                {
                                    int index = 0;
                                    Int32.TryParse(item.wnm_originalfield.Replace("Column", ""), out index);

                                    item.wnm_originalfield = "Column" + (index - 1);
                                }

                                Boolean columnExists = result.Tables[0].Columns.Contains(item.wnm_originalfield);
                                if (columnExists == false)
                                {
                                    ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                                    {
                                        lfu_status      = 'E',
                                        lfu_Err_type    = 'C',
                                        lfu_Err_no      = 1,
                                        lfu_Err_Column  = wnm_originalfield,
                                        lfu_Err_Message = "ไม่พบ Column " + wnm_originalfield
                                    });
                                }

                                if (columnExists)
                                {
                                    var chkResult = result.Tables[0].Select("[" + item.wnm_originalfield + "]" + " is null");

                                    if (chkResult.Length > 0)
                                    {
                                        ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                                        {
                                            lfu_status      = 'E',
                                            lfu_Err_type    = 'N',
                                            lfu_Err_no      = 1,
                                            lfu_Err_Column  = wnm_originalfield,
                                            lfu_Err_Message = "กรุณาตรวจสอบข้อมูล Column " + wnm_originalfield + " จะต้องไม่เท่ากับค่าว่าง"
                                        });
                                    }

                                    //if (item.wnm_type == "Date")
                                    //{
                                    //    var FieldDateType = result.Tables[0].Columns[item.wnm_originalfield].DataType.ToString();

                                    //    if(FieldDateType == "System.String")
                                    //    {
                                    //        try
                                    //        {

                                    //        }
                                    //        catch()
                                    //        {

                                    //        }

                                    //    }
                                    //}
                                }
                            }

                            var x = ErrorMessage;
                        }
                    }
                }
                #endregion
                #region ReadCSV
                else if (Path.GetExtension(fileEntry.Name) == ".csv")
                {
                    using (var stream = File.Open(path, FileMode.Open, FileAccess.Read))
                    {
                        var reader = ExcelReaderFactory.CreateCsvReader(stream, new ExcelReaderConfiguration()
                        {
                            FallbackEncoding      = Encoding.GetEncoding(1252),
                            AutodetectSeparators  = new char[] { ',', ';', '\t', '|', '#' },
                            LeaveOpen             = false,
                            AnalyzeInitialCsvRows = 0,
                        });

                        DataSet result = new DataSet();

                        ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                        {
                            lfu_status      = 'I',
                            lfu_Err_type    = 'I',
                            lfu_Err_no      = 1,
                            lfu_Err_Column  = "Total",
                            lfu_Err_Message = result.Tables[0].Rows.Count.ToString()
                        });
                        //First row is header
                        if (MappingTemplate.mp_firstlineisheader == true)
                        {
                            result = reader.AsDataSet(new ExcelDataSetConfiguration()
                            {
                                ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
                                {
                                    UseHeaderRow = true
                                }
                            }
                                                      );
                        }
                        else
                        {
                            result = reader.AsDataSet();
                        }

                        var ee = result.Tables[0];
                        foreach (WHONetMappingListsDTO item in WHONetColumnMandatory)
                        {
                            var wnm_originalfield = item.wnm_originalfield;
                            if (MappingTemplate.mp_firstlineisheader == false)
                            {
                                int index = 0;
                                Int32.TryParse(item.wnm_originalfield.Replace("Column", ""), out index);

                                item.wnm_originalfield = "Column" + (index - 1);
                            }

                            Boolean columnExists = result.Tables[0].Columns.Contains(item.wnm_originalfield);
                            if (columnExists == false)
                            {
                                ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                                {
                                    lfu_status      = 'E',
                                    lfu_Err_type    = 'C',
                                    lfu_Err_no      = 1,
                                    lfu_Err_Column  = wnm_originalfield,
                                    lfu_Err_Message = "ไม่พบ Column " + wnm_originalfield
                                });
                            }

                            if (columnExists)
                            {
                                var chkResult = result.Tables[0].Select(item.wnm_originalfield + " = ''");

                                if (chkResult.Length > 0)
                                {
                                    ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                                    {
                                        lfu_status      = 'E',
                                        lfu_Err_type    = 'N',
                                        lfu_Err_no      = 1,
                                        lfu_Err_Column  = wnm_originalfield,
                                        lfu_Err_Message = "กรุณาตรวจสอบข้อมูล Column " + wnm_originalfield + " จะต้องไม่เท่ากับค่าว่าง"
                                    });
                                }
                            }
                        }

                        var x = ErrorMessage;
                    }
                }
                #endregion
                #region ReadText
                else if (Path.GetExtension(fileEntry.Name) == ".txt")
                {
                    string    line;
                    DataTable dt           = new DataTable();
                    string    tempFilename = Guid.NewGuid().ToString() + ".txt";
                    //var path = Path.Combine(@"D:\Work\02-DMSC ALISS\TEMP\", tempFilename);
                    //var ms = new MemoryStream();
                    //await fileEntry.Data.CopyToAsync(ms);
                    //using (FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write))
                    //{
                    //    ms.WriteTo(file);
                    //}

                    //using (TextReader tr = File.OpenText(@"D:\Work\02-DMSC ALISS\TEMP\" + tempFilename))
                    using (TextReader tr = File.OpenText(path))
                    {
                        while ((line = tr.ReadLine()) != null)
                        {
                            string[] items = line.Split('\t');

                            if (dt.Columns.Count == 0)
                            {
                                if (MappingTemplate.mp_firstlineisheader == false)
                                {
                                    for (int i = 0; i < items.Length; i++)
                                    {
                                        dt.Columns.Add(new DataColumn("Column" + i, typeof(string)));
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < items.Length; i++)
                                    {
                                        dt.Columns.Add(new DataColumn(items[i].ToString(), typeof(string)));
                                    }
                                }
                            }
                            dt.Rows.Add(items);
                        }
                    }

                    File.Delete(path);
                    ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                    {
                        lfu_status      = 'I',
                        lfu_Err_type    = 'I',
                        lfu_Err_no      = 1,
                        lfu_Err_Column  = "Total",
                        lfu_Err_Message = (dt.Rows.Count - 1).ToString()
                    });

                    foreach (WHONetMappingListsDTO item in WHONetColumnMandatory)
                    {
                        var wnm_originalfield = item.wnm_originalfield;
                        if (MappingTemplate.mp_firstlineisheader == false)
                        {
                            int index = 0;
                            Int32.TryParse(item.wnm_originalfield.Replace("Column", ""), out index);

                            item.wnm_originalfield = "Column" + (index - 1);
                        }

                        Boolean columnExists = dt.Columns.Contains(item.wnm_originalfield);
                        if (columnExists == false)
                        {
                            ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                            {
                                lfu_status      = 'E',
                                lfu_Err_type    = 'C',
                                lfu_Err_no      = 1,
                                lfu_Err_Column  = wnm_originalfield,
                                lfu_Err_Message = "ไม่พบ Column " + wnm_originalfield
                            });
                        }

                        if (columnExists)
                        {
                            var chkResult = dt.Select(item.wnm_originalfield + " = ''");

                            if (chkResult.Length > 0)
                            {
                                ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                                {
                                    lfu_status      = 'E',
                                    lfu_Err_type    = 'N',
                                    lfu_Err_no      = 1,
                                    lfu_Err_Column  = wnm_originalfield,
                                    lfu_Err_Message = "กรุณาตรวจสอบข้อมูล Column " + wnm_originalfield + " จะต้องไม่เท่ากับค่าว่าง"
                                });
                            }
                        }
                    }
                }
                #endregion
                else
                {
                    string tempFilename = Guid.NewGuid().ToString() + ".dbf";

                    //var path = Path.Combine(@"D:\Work\02-DMSC ALISS\TEMP\", tempFilename);

                    //bool exists = System.IO.Directory.Exists(@"D:\Work\02-DMSC ALISS\TEMP\");

                    //if (!exists)
                    //    System.IO.Directory.CreateDirectory(@"D:\Work\02-DMSC ALISS\TEMP\");

                    //using (FileStream file = new FileStream(path, FileMode.Create))
                    //{
                    //    try
                    //    {
                    //        await fileEntry.Data.CopyToAsync(file);
                    //    }
                    //    catch (Exception ex)
                    //    {

                    //    }
                    //    finally
                    //    {
                    //        file.Flush();
                    //    }
                    //}

                    var options = new DbfDataReaderOptions
                    {
                        Encoding = Encoding.GetEncoding(874)
                    };


                    using (var dbfDataReader = new DbfDataReader.DbfDataReader(path, options))
                    //using (var dbfDataReader = new DbfDataReader.DbfDataReader(@"D:\Work\02-DMSC ALISS\TEMP\" + tempFilename, options))
                    {
                        ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                        {
                            lfu_status      = 'I',
                            lfu_Err_type    = 'I',
                            lfu_Err_no      = 1,
                            lfu_Err_Column  = "Total",
                            lfu_Err_Message = dbfDataReader.DbfTable.Header.RecordCount.ToString()
                        });

                        while (dbfDataReader.Read())
                        {
                            //Validate Mandatory Field
                            foreach (WHONetMappingListsDTO item in WHONetColumnMandatory)
                            {
                                var columnExists = dbfDataReader.DbfTable.Columns.FirstOrDefault(x => x.Name == item.wnm_originalfield);
                                //var ll = dbfDataReader.DbfTable.Rea
                                if (columnExists != null)
                                {
                                    if (dbfDataReader[item.wnm_originalfield] == "" || dbfDataReader[item.wnm_originalfield] == null)
                                    {
                                        if (ErrorMessage.FirstOrDefault(x => x.lfu_Err_type == 'N' && x.lfu_Err_Column == item.wnm_originalfield) == null)
                                        {
                                            ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                                            {
                                                lfu_status      = 'E',
                                                lfu_Err_type    = 'N',
                                                lfu_Err_no      = 1,
                                                lfu_Err_Column  = item.wnm_originalfield,
                                                lfu_Err_Message = "กรุณาตรวจสอบข้อมูล Column " + item.wnm_originalfield + " จะต้องไม่เท่ากับค่าว่าง"
                                            });
                                            var ccc = dbfDataReader[item.wnm_originalfield];
                                        }
                                    }
                                }
                                else
                                {
                                    if (ErrorMessage.FirstOrDefault(x => x.lfu_Err_type == 'C' && x.lfu_Err_Column == item.wnm_originalfield) == null)
                                    {
                                        ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                                        {
                                            lfu_status      = 'E',
                                            lfu_Err_type    = 'C',
                                            lfu_Err_no      = 1,
                                            lfu_Err_Column  = item.wnm_originalfield,
                                            lfu_Err_Message = "ไม่พบ Column " + item.wnm_originalfield
                                        });
                                    }
                                }
                            }
                            row++;
                        }
                        var x = ErrorMessage;

                        //using (FileStream file = new FileStream(@"D:\Work\02-DMSC ALISS\TEMP\"+ fileEntry.Name, FileMode.Create))
                        //{
                        //    try
                        //    {
                        //        await fileEntry.Data.CopyToAsync(file);
                        //    }
                        //    catch (Exception ex)
                        //    {

                        //    }
                        //    finally
                        //    {
                        //        file.Flush();
                        //    }
                        //}


                        //var zipStream = new MemoryStream();


                        //using (var compressedFileStream = new MemoryStream())
                        //{
                        //    //compressedFileStream.Seek(0, SeekOrigin.Begin);
                        //    using (var zipArchive = new ZipArchive(compressedFileStream, ZipArchiveMode.Create, false))
                        //    {
                        //        var zipEntry = zipArchive.CreateEntry(fileEntry.Name);
                        //        using (var zipEntryStream = zipEntry.Open())
                        //        {
                        //            try
                        //            {
                        //                await fileEntry.Data.CopyToAsync(zipEntryStream);
                        //                //fileEntry.Data.CopyTo(zipEntryStream);
                        //            }
                        //            catch (Exception ex)
                        //            {

                        //            }
                        //            finally
                        //            {
                        //                zipEntryStream.Flush();
                        //            }
                        //        }
                        //    }

                        //    using (var fileStream = new FileStream(@"D:\Work\02-DMSC ALISS\TEMP\test.zip", FileMode.Create))
                        //    {
                        //        var bytes = compressedFileStream.GetBuffer();
                        //        fileStream.Write(bytes, 0, bytes.Length);
                        //        try
                        //        {
                        //            await compressedFileStream.CopyToAsync(fileStream);
                        //        }
                        //        catch (Exception ex)
                        //        {

                        //        }
                        //        finally
                        //        {
                        //            fileStream.Flush();
                        //        }
                        //    }
                        //}
                        //using (var outStream = new MemoryStream())
                        //{
                        //    using (var archive = new ZipArchive(outStream, ZipArchiveMode.Create, true))
                        //    {
                        //        var fileInArchive = archive.CreateEntry(fileEntry.Name, CompressionLevel.Optimal);
                        //        using (var entryStream = fileInArchive.Open())

                        //            await fileEntry.Data.CopyToAsync(entryStream);

                        //    }
                        //    using (var fileStream = new FileStream(@"D:\test.zip", FileMode.Create))
                        //    {
                        //        outStream.Seek(0, SeekOrigin.Begin);
                        //        outStream.CopyTo(fileStream);
                        //    }
                        //}
                    }
                    //File.Delete(path);
                }


                var chkError = ErrorMessage.FirstOrDefault(x => x.lfu_status == 'E');
                if (chkError != null)
                {
                    File.Delete(path);
                }
                else
                {
                    ErrorMessage.Add(new LabFileUploadErrorMessageDTO
                    {
                        lfu_status      = 'I',
                        lfu_Err_type    = 'P',
                        lfu_Err_no      = 1,
                        lfu_Err_Column  = "path",
                        lfu_Err_Message = path
                    });
                }
            }
            catch (Exception ex)
            {
            }

            return(ErrorMessage);
        }
        public MappingDataDTO Get_MappingDataActiveWithModel([FromBody] MappingDataDTO model)
        {
            var objReturn = _service.GetMappingDataActiveWithModel(model);

            return(objReturn);
        }
        public MappingDataDTO Get_chkDuplicateMappingApproved([FromBody] MappingDataDTO model)
        {
            var objReturn = _service.chkDuplicateMappingApproved(model);

            return(objReturn);
        }
        public MappingDataDTO Post_CopyMappingData([FromBody] MappingDataDTO model)
        {
            var objReturn = _service.CopyMappingData(model);

            return(objReturn);
        }
Exemplo n.º 12
0
        public MappingDataDTO SaveMappingData(MappingDataDTO model)
        {
            log.MethodStart();

            var            currentDateTime = DateTime.Now;
            MappingDataDTO objReturn       = new MappingDataDTO();

            using (var trans = _db.Database.BeginTransaction())
            {
                try
                {
                    var objModel = new TRMapping();

                    if (model.mp_status == 'N')
                    {
                        objModel = _mapper.Map <TRMapping>(model);

                        objModel.mp_createdate = currentDateTime;
                        objModel.mp_updatedate = currentDateTime;

                        _db.TRMappings.Add(objModel);
                    }
                    else if (model.mp_status == 'E')
                    {
                        objModel               = _db.TRMappings.FirstOrDefault(x => x.mp_id == model.mp_id);
                        objModel.mp_status     = model.mp_status;
                        objModel.mp_version    = model.mp_version;
                        objModel.mp_startdate  = model.mp_startdate;
                        objModel.mp_enddate    = model.mp_enddate;
                        objModel.mp_program    = model.mp_program;
                        objModel.mp_filetype   = model.mp_filetype;
                        objModel.mp_dateformat = model.mp_dateformat;
                        objModel.mp_AntibioticIsolateOneRec = model.mp_AntibioticIsolateOneRec;
                        objModel.mp_firstlineisheader       = model.mp_firstlineisheader;
                        objModel.mp_updateuser = model.mp_updateuser;
                        objModel.mp_updatedate = currentDateTime;
                    }
                    else if (model.mp_status == 'A')
                    {
                        objModel                 = _db.TRMappings.FirstOrDefault(x => x.mp_id == model.mp_id);
                        objModel.mp_status       = model.mp_status;
                        objModel.mp_version      = objModel.mp_version + 0.01M;
                        objModel.mp_approveduser = model.mp_approveduser;
                        objModel.mp_approveddate = currentDateTime;
                        objModel.mp_updateuser   = model.mp_updateuser;
                        objModel.mp_updatedate   = currentDateTime;

                        var oldVersion = _db.TRMappings.OrderByDescending(x => x.mp_version).FirstOrDefault(x => x.mp_lab == model.mp_lab &&
                                                                                                            x.mp_hos_code == model.mp_hos_code &&
                                                                                                            x.mp_status == 'A' &&
                                                                                                            x.mp_program == model.mp_program &&
                                                                                                            x.mp_filetype == model.mp_filetype &&
                                                                                                            x.mp_startdate < model.mp_startdate &&
                                                                                                            x.mp_enddate == null &&
                                                                                                            x.mp_flagdelete == false);
                        if (oldVersion != null)
                        {
                            oldVersion.mp_enddate = model.mp_startdate.Value.AddDays(-1);
                        }
                    }


                    #region Save Log Process ...
                    _db.LogProcesss.Add(new LogProcess()
                    {
                        log_usr_id     = (objModel.mp_updateuser ?? objModel.mp_createuser),
                        log_mnu_id     = "",
                        log_mnu_name   = "Mapping",
                        log_tran_id    = objModel.mp_id.ToString(),
                        log_action     = (objModel.mp_status == 'N' ? "New" : "Update"),
                        log_desc       = "Update Mapping ",
                        log_createuser = "******",
                        log_createdate = currentDateTime
                    });
                    #endregion

                    _db.SaveChanges();

                    trans.Commit();

                    objReturn = _mapper.Map <MappingDataDTO>(objModel);
                }
                catch (Exception ex)
                {
                    // TODO: Handle failure
                    trans.Rollback();
                }
                finally
                {
                    trans.Dispose();
                }
            }

            log.MethodFinish();

            return(objReturn);
        }
Exemplo n.º 13
0
        public MappingDataDTO CopyMappingData(MappingDataDTO objParam)
        {
            log.MethodStart();

            var            currentDateTime = DateTime.Now;
            MappingDataDTO objReturn       = new MappingDataDTO();

            using (var trans = _db.Database.BeginTransaction())
            {
                #region Create Mapping...
                var Mapping = _db.TRMappings.FirstOrDefault(x => x.mp_id == objParam.mp_id);
                Mapping.mp_id         = Guid.NewGuid();
                Mapping.mp_mst_code   = objParam.mp_mst_code;
                Mapping.mp_status     = 'E';
                Mapping.mp_version    = Math.Floor(objParam.mp_version);
                Mapping.mp_hos_code   = objParam.mp_hos_code;
                Mapping.mp_lab        = objParam.mp_lab;
                Mapping.mp_startdate  = objParam.mp_startdate;
                Mapping.mp_enddate    = null;
                Mapping.mp_createuser = objParam.mp_createuser;
                Mapping.mp_createdate = currentDateTime;
                Mapping.mp_updateuser = objParam.mp_createuser;
                Mapping.mp_updatedate = currentDateTime;
                _db.TRMappings.Add(Mapping);
                #endregion

                #region Create WHONetMapping...

                var WHONetMapping = _db.TRWHONetMappings.Where(w => w.wnm_mappingid == objParam.mp_id &&
                                                               w.wnm_flagdelete == false);


                if (WHONetMapping != null)
                {
                    foreach (var w in WHONetMapping)
                    {
                        w.wnm_id         = Guid.NewGuid();
                        w.wnm_mappingid  = Mapping.mp_id;
                        w.wnm_status     = 'N';
                        w.wnm_createuser = objParam.mp_createuser;
                        w.wnm_createdate = currentDateTime;
                        w.wnm_updateuser = objParam.mp_createuser;
                        w.wnm_updatedate = null;
                    }

                    _db.TRWHONetMappings.AddRange(WHONetMapping);
                }
                #endregion

                #region Create SpecimenMapping...
                var SpecimenMapping = _db.TRSpecimenMappings.Where(s => s.spm_mappingid == objParam.mp_id &&
                                                                   s.spm_flagdelete == false);

                if (SpecimenMapping != null)
                {
                    foreach (var s in SpecimenMapping)
                    {
                        s.spm_id         = Guid.NewGuid();
                        s.spm_mappingid  = Mapping.mp_id;
                        s.spm_status     = 'N';
                        s.spm_createuser = objParam.mp_createuser;
                        s.spm_createdate = currentDateTime;
                        s.spm_updateuser = objParam.mp_createuser;
                        s.spm_updatedate = currentDateTime;
                    }

                    _db.TRSpecimenMappings.AddRange(SpecimenMapping);
                }
                #endregion

                #region Create OrganismMapping...
                var OrganismMapping = _db.TROrganismMappings.Where(o => o.ogm_mappingid == objParam.mp_id &&
                                                                   o.ogm_flagdelete == false);

                if (OrganismMapping != null)
                {
                    foreach (var o in OrganismMapping)
                    {
                        o.ogm_id         = Guid.NewGuid();
                        o.ogm_mappingid  = Mapping.mp_id;
                        o.ogm_status     = 'N';
                        o.ogm_createuser = objParam.mp_createuser;
                        o.ogm_createdate = currentDateTime;
                        o.ogm_updateuser = objParam.mp_createuser;
                        o.ogm_updatedate = currentDateTime;
                    }

                    _db.TROrganismMappings.AddRange(OrganismMapping);
                }
                #endregion

                #region Create WardTypeMapping...
                var WardTypeMapping = _db.TRWardTypeMappings.Where(wd => wd.wdm_mappingid == objParam.mp_id &&
                                                                   wd.wdm_flagdelete == false);

                if (WardTypeMapping != null)
                {
                    foreach (var wd in WardTypeMapping)
                    {
                        wd.wdm_id         = Guid.NewGuid();
                        wd.wdm_mappingid  = Mapping.mp_id;
                        wd.wdm_status     = 'N';
                        wd.wdm_createuser = objParam.mp_createuser;
                        wd.wdm_createdate = currentDateTime;
                        wd.wdm_updateuser = objParam.mp_createuser;
                        wd.wdm_updatedate = currentDateTime;
                    }

                    _db.TRWardTypeMappings.AddRange(WardTypeMapping);
                }
                #endregion

                #region Save Log Process ...
                _db.LogProcesss.Add(new LogProcess()
                {
                    log_usr_id     = (Mapping.mp_updateuser ?? Mapping.mp_createuser),
                    log_mnu_id     = "",
                    log_mnu_name   = "Mapping",
                    log_tran_id    = Mapping.mp_id.ToString(),
                    log_action     = (Mapping.mp_status == 'N' ? "New" : "Update"),
                    log_desc       = "Copy Mapping ",
                    log_createuser = "******",
                    log_createdate = currentDateTime
                });
                #endregion

                _db.SaveChanges();

                trans.Commit();

                objReturn = _mapper.Map <MappingDataDTO>(Mapping);
            }
            log.MethodFinish();
            return(objReturn);
        }
Exemplo n.º 14
0
        public async Task <MappingDataDTO> CopyMappingDataAsync(MappingDataDTO model)
        {
            var mapping = await _apiHelper.PostDataAsync <MappingDataDTO>("mapping_api/Post_CopyMappingData", model);

            return(mapping);
        }