public SingleResponeMessage <ExplanationDetailInfo> Get(int id, string _userID)
        {
            SingleResponeMessage <ExplanationDetailInfo> ret = new SingleResponeMessage <ExplanationDetailInfo>();

            try
            {
                ExplanationDetailInfo item = ExplanationService.GetInstance().getDetailExplanation(id, _userID);
                if (item == null)
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "001";
                    ret.err.msgString = "no Explanation found";
                    return(ret);
                }
                ret.item      = item;
                ret.isSuccess = true;
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
        public ActionMessage Post([FromBody] ExplanationInfo _explanation)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = ExplanationService.GetInstance().createExplanation(_explanation, GetUserId());
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
        public ActionMessage Delete(int id, string _userID)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = ExplanationService.GetInstance().DeleteExplanation(id, GetUserId(), _userID);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
        public ActionMessage DeleteAll(string ids)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = ExplanationService.GetInstance().DeleteAll(ids);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
        public async Task <ActionMessage> Put(int id, [FromForm] ExplanationInfo _explanation, [FromForm] List <IFormFile> files)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = await ExplanationService.GetInstance().EditExplanation(id, _explanation, GetUserId(), files);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
        public async Task <ActionMessage> PostwithAttFile([FromForm] ExplanationInfo explanationObj, [FromForm] List <IFormFile> files)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = await ExplanationService.GetInstance().CreateExplanation2(explanationObj, GetUserId(), files);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
        public ListResponeMessage <ExplanationInfo> GetListWithCondition([FromQuery] ExplanationSeachCriteria _criteria, string _userID)
        {
            ListResponeMessage <ExplanationInfo> ret = new ListResponeMessage <ExplanationInfo>();

            try
            {
                ret.isSuccess    = true;
                ret.data         = ExplanationService.GetInstance().getAllExplanationWwithCondition(_criteria, _userID);
                ret.totalRecords = ExplanationService.GetInstance().getTotalRecords(_criteria, _userID);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "005";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
        public ListResponeMessage <ExplanationInfo> GetList(int pageSize = 10, int pageIndex = 0, string _userID = "")
        {
            ListResponeMessage <ExplanationInfo> ret = new ListResponeMessage <ExplanationInfo>();

            try
            {
                ret.isSuccess    = true;
                ret.data         = ExplanationService.GetInstance().getAllExplanation(pageSize, pageIndex, _userID);
                ret.totalRecords = ExplanationService.GetInstance().getTotalRecords(null, _userID);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "005";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
 public void GetLadyGagaExplanation()
 {
     ExplanationItem explanationItem = new ExplanationService().GetExplanation("Lady Gaga");
     Assert.That(explanationItem.Explanation.Length > 0);
 }
 public void GetUnknowExplanation()
 {
     ExplanationItem explanationItem = new ExplanationService().GetExplanation("unknown");
     Assert.That(explanationItem.Explanation.Length > 0);
 }
Beispiel #11
0
        public static MemoryStream GetTemplate(int id, string path, out string code, string _userID)
        {
            var memoryStream           = new MemoryStream();
            ExplanationDetailInfo item = ExplanationService.GetInstance().getDetailExplanation(id, _userID);

            // var index = item.ProposalType - 1;
            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                fileStream.CopyTo(memoryStream);
            code = item.ProposalCode;
            using (var document = WordprocessingDocument.Open(memoryStream, true))
            {
                document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document
                DateTime date        = DateTime.Now;
                string   currentDate = "Ngày " + date.ToString("dd/MM/yyyy");
                var      body        = document.MainDocumentPart.Document.Body;
                var      paras       = body.Elements <Paragraph>();

                var itemName = "";
                foreach (ItemPropsalInfo record in item.Items)
                {
                    itemName = itemName + record.ItemName + ", ";
                }
                itemName = itemName.Substring(0, itemName.Length - 1);

                foreach (var text in body.Descendants <Text>())
                {
                    text.Text = text.Text.Replace("#", "");
                    text.Text = text.Text.Replace("itemname", WordUtils.checkNull(itemName));
                    text.Text = text.Text.Replace("nbNumber", WordUtils.checkNull(item.NBNum));
                    text.Text = text.Text.Replace("xnNumber", WordUtils.checkNull(item.XNNum));
                    text.Text = text.Text.Replace("numberMachine", WordUtils.checkNull(item.Available.ToString()));
                    text.Text = text.Text.Replace("explainationcode", WordUtils.checkNull(item.ExplanationCode));
                    text.Text = text.Text.Replace("reason", WordUtils.checkNull(item.Comment));
                    text.Text = text.Text.Replace("tncb", WordUtils.checkNull(item.TNCB));
                    text.Text = text.Text.Replace("dbltcn", WordUtils.checkNull(item.DBLTCN));
                    text.Text = text.Text.Replace("nvh", WordUtils.checkNull(item.NVHTTB));
                    text.Text = text.Text.Replace("dtnl", WordUtils.checkNull(item.DTNL));
                    text.Text = text.Text.Replace("nql", WordUtils.checkNull(item.NQL));
                    text.Text = text.Text.Replace("hqktcxh", WordUtils.checkNull(item.HQKTXH));
                }
                List <int> Checks = new List <int>();
                if (item.Necess == true)
                {
                    Checks.Add(0);
                }
                else
                {
                    Checks.Add(1);
                }

                if (item.Suitable == true)
                {
                    Checks.Add(2);
                }
                else
                {
                    Checks.Add(3);
                }

                if (item.IsAvailable == true)
                {
                    Checks.Add(4);
                }
                else
                {
                    Checks.Add(5);
                }
                int i = 0;
                foreach (SdtContentCheckBox ctrl in body.Descendants <SdtContentCheckBox>())
                {
                    if (Checks.IndexOf(i) > -1)
                    {
                        ctrl.Checked.Val = OnOffValues.One;
                        ctrl.Parent.Parent.Descendants <Run>().First().GetFirstChild <Text>().Text = "☒";
                    }
                    i++;
                }
                document.Save();
                document.Close();
            }
            return(memoryStream);
        }