예제 #1
0
        public SingleResponeMessage <SurveyDetailInfo> Get(int id, string _userID)
        {
            SingleResponeMessage <SurveyDetailInfo> ret = new SingleResponeMessage <SurveyDetailInfo>();

            try
            {
                SurveyDetailInfo item = SurveyService.GetInstance().GetDetailSurvey(id, _userID);
                if (item == null)
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "001";
                    ret.err.msgString = "no Survey 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);
        }
예제 #2
0
        public async Task <HttpResponseMessage> Get_survey_answer(int id)
        {
            IStateFactory <IEnumerable <surveyAnswer>, SurveyAnswerSingleState> _stateFactory = new SurveyAnswerSingleFactory(Request);
            var instance = SurveyService.GetInstance();
            var token    = GetToken();

            var questions = await instance.GetSurveyResponses(id, token);

            if (questions.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, _stateFactory.Create(questions.Result), "application/json"));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, questions.Message), "application/problem+json"));
        }
예제 #3
0
        public ActionMessage Post([FromBody] SurveyInfo _survey)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = SurveyService.GetInstance().createSurvey(_survey, GetUserId());
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #4
0
        public ActionMessage DeleteAll(string ids)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = SurveyService.GetInstance().DeleteAll(ids);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #5
0
        public ActionMessage Delete(int id, string _userID)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = SurveyService.GetInstance().DeleteSurvey(id, GetUserId(), _userID);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #6
0
        public async Task <ActionMessage> Put(int id, [FromForm] SurveyInfo _Survey, [FromForm] List <IFormFile> files)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = await SurveyService.GetInstance().editSurvey(id, _Survey, GetUserId(), files);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #7
0
        public async Task <ActionMessage> PostwithAttFile([FromForm] SurveyInfo SurveyObj, [FromForm] List <IFormFile> files)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = await SurveyService.GetInstance().createSurvey2(SurveyObj, GetUserId(), files);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #8
0
        public ListResponeMessage <SurveyInfo> GetListWithCondition([FromQuery] SurveySeachCriteria _criteria, string _userID)
        {
            ListResponeMessage <SurveyInfo> ret = new ListResponeMessage <SurveyInfo>();

            try
            {
                ret.isSuccess    = true;
                ret.data         = SurveyService.GetInstance().GetAllSurveyWithCondition(_criteria, _userID);
                ret.totalRecords = SurveyService.GetInstance().GetTotalRecords(_criteria, _userID);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "005";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #9
0
        public ListResponeMessage <SurveyInfo> GetList(int pageSize = 10, int pageIndex = 0, string _userID = "")
        {
            ListResponeMessage <SurveyInfo> ret = new ListResponeMessage <SurveyInfo>();

            try
            {
                ret.isSuccess    = true;
                ret.data         = SurveyService.GetInstance().GetAllSurvey(pageSize, pageIndex, _userID);
                ret.totalRecords = SurveyService.GetInstance().GetTotalRecords(null, _userID);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "005";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #10
0
        public async Task <HttpResponseMessage> PostAnswer([FromBody]  SurveyQuestionAnswer[] body, int id)
        {
            var instance = SurveyService.GetInstance();

            var token = GetToken();

            if (token == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, new Forbidden(Request.RequestUri, "token not present in authorization header or not valid"), "application/problem+json"));
            }

            var res = await instance.PostSurveyAnswer(new CreateSurveyAnswer { authorId = token, eventId = id, questions = body });

            if (res.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { }, "application/json"));
            }

            return(Request.CreateResponse(HttpStatusCode.Conflict, new Conflict(Request.RequestUri, res.Message), "application/problem+json"));
        }
예제 #11
0
        public static MemoryStream GetTempPlate(int id, string path, out string code, string _userID)
        {
            var memoryStream      = new MemoryStream();
            SurveyDetailInfo item = SurveyService.GetInstance().GetDetailSurvey(id, _userID);

            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   curDate     = date.ToString("dd/MM/yyyy");
                string   currentdate = "Ngày " + date.Day + " tháng " + date.Month + " năm" + date.Year;
                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);
                List <string>         headers = new List <string>();
                List <List <string> > items   = new List <List <string> >();
                headers.Add("STT");
                headers.Add("Tên linh kiện, tài sản");
                headers.Add("ĐVT");
                headers.Add("Số Lượng");
                headers.Add("Ghi Chú");

                var sttIndex = 1;

                foreach (ItemSurveyInfo record in item.SurveyItems)
                {
                    List <string> row = new List <string>();
                    row.Add(sttIndex.ToString());
                    row.Add(record.ItemName);
                    row.Add(record.ItemUnit);
                    row.Add(record.ItemAmount.ToString());
                    row.Add(record.Note);
                    items.Add(row);
                    sttIndex++;
                }
                Table tableData = CreateTable(headers, items);


                foreach (var text in body.Descendants <Text>())
                {
                    text.Text = text.Text.Replace("#", "");
                    text.Text = text.Text.Replace("proposalcode", WordUtils.checkNull(item.ProposalCode));
                    text.Text = text.Text.Replace("surveycode", WordUtils.checkNull(item.SurveyCode));
                    text.Text = text.Text.Replace("solution", WordUtils.checkNull(item.SolutionText));
                    text.Text = text.Text.Replace("validtext", WordUtils.checkNull(item.ValidText));
                    text.Text = text.Text.Replace("proposaldate", WordUtils.checkNull(item.ProposalDate.ToString("dd/MM/yyyy")));
                    text.Text = text.Text.Replace("curdate", WordUtils.checkNull(curDate));
                    text.Text = text.Text.Replace("currentdate", WordUtils.checkNull(currentdate));
                    text.Text = text.Text.Replace("itemname", WordUtils.checkNull(itemName));
                    text.Text = text.Text.Replace("depart", WordUtils.checkNull(item.DepartmentName));


                    if (text.Text == "lstItem")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData, textP2);
                        textP1.Remove();
                    }
                }
                List <int> Checks = new List <int>();

                Checks.Add(item.Solution - 1);

                if (item.IsSample == true)
                {
                    Checks.Add(4);
                }

                if (item.Valid == true)
                {
                    Checks.Add(5);
                }
                else
                {
                    Checks.Add(6);
                }

                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);
        }
예제 #12
0
 public void initialize()
 {
     surveyService = SurveyService.GetInstance();
 }