Exemple #1
0
        public async Task <ActionMessage> createSurvey2(SurveyInfo _Survey, string _userI, [FromForm] List <IFormFile> files)
        {
            ActionMessage        ret           = new ActionMessage();
            int                  insetId       = -1;
            SqlConnectionFactory sqlConnection = new SqlConnectionFactory();

            using (SqlConnection connection = sqlConnection.GetConnection())
            {
                try
                {
                    UserLogInfo info = new UserLogInfo();
                    info.Action      = "Insert";
                    info.Description = "ngày : " + _Survey.InTime + " code : KS-" + _Survey.ProposalCode
                                       + " trạng thái : " + _Survey.Status;
                    info.Feature  = TableFile.Proposal.ToString();
                    info.Time     = DateTime.Now;
                    info.UserName = _userI;
                    info.UserID   = 1;
                    UserService.GetInstance().TrackUserAction(info);
                    insetId = SurveyDataLayer.GetInstance().InsertSurvey(connection, _Survey, _userI);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            if (insetId > -1)
            {
                ret.id = insetId;
                using (SqlConnection connection = sqlConnection.GetConnection())
                {
                    try
                    {
                        foreach (ItemSurveyInfo item in _Survey.SurveyItems)
                        {
                            ProposalDataLayer.GetInstance().InsertSurveyItem(connection, item, insetId, _userI);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }

                foreach (var item in files)
                {
                    DocumentInfo documentInfo = new DocumentInfo();
                    documentInfo.TableName = TableFile.Survey.ToString();
                    documentInfo.PreferId  = insetId.ToString();
                    documentInfo.Link      = DateTime.Now.ToString("yyMMddHHmmssfff") + "-" + Utils.ChuyenTVKhongDau(item.FileName);
                    documentInfo.FileName  = item.FileName;
                    documentInfo.Length    = item.Length.ToString();
                    documentInfo.Type      = item.ContentType;
                    await FilesHelpers.UploadFile(TableFile.Survey.ToString(), insetId.ToString(), item, documentInfo.Link);

                    DocumentService.GetInstance().InsertDocument(documentInfo, _userI.ToString());
                }
                ret.isSuccess = true;
            }
            else
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "lỗi thêm phiếu khảo sát";
                ret.err.msgString = "lỗi thêm phiếu khảo sát";
            }
            return(ret);
        }