public IActionResult Save([FromBody] SurveyForm_VM surveyForm)
        {
            CommonResponse <int> response = new CommonResponse <int>();

            if (surveyForm != null)
            {
                response.status = _surveyRepository.Save(surveyForm);
                if (response.status == 1)
                {
                    response.message = Message.surveySave;
                }
                else
                {
                    response.message = Message.surveySaveError;
                }
            }
            else
            {
                response.message = Message.badRequest;
            }
            return(Ok(response));
        }
示例#2
0
        /// <summary>
        /// Save fill-up survey
        /// </summary>
        /// <param name="surveyForm"></param>
        /// <returns></returns>
        public int Save(SurveyForm_VM surveyForm)
        {
            int ret = 0;

            using (var dbcxtransaction = _context.Database.BeginTransaction())
            {
                try
                {
                    // Save user's info
                    var obj = new CRM_CommentCardResultsHeader();
                    obj.cc_id       = surveyForm.CommentCard.cc_id;
                    obj.Customer_ID = Guid.NewGuid();
                    obj.Store_ID    = surveyForm.Store_ID;
                    obj.Storeno     = surveyForm.Storeno;

                    foreach (var user in surveyForm.SysFields)
                    {
                        if (user.FieldID == USERINFO.FirstName.ToString())
                        {
                            obj.FirstName = user.UserAnswer;
                        }
                        else if (user.FieldID == USERINFO.LastName.ToString())
                        {
                            obj.LastName = user.UserAnswer;
                        }
                        else if (user.FieldID == USERINFO.Email.ToString())
                        {
                            obj.Email = user.UserAnswer;
                        }
                        else if (user.FieldID == USERINFO.Mobile.ToString())
                        {
                            obj.Mobile = user.UserAnswer;
                        }
                        else if (user.FieldID == USERINFO.Birthday.ToString() && user.UserAnswer != null)
                        {
                            obj.Birthday = DateTime.Parse(user.UserAnswer);
                        }
                        else if (user.FieldID == USERINFO.Gender.ToString())
                        {
                            obj.Gender = user.UserAnswer;
                        }
                        else if (user.FieldID == USERINFO.Nationality.ToString() && user.UserAnswer != null)
                        {
                            obj.Nationality = Convert.ToInt32(user.UserAnswer);
                        }
                        else if (user.FieldID == USERINFO.COR.ToString() && user.UserAnswer != null)
                        {
                            obj.COR = Convert.ToInt32(user.UserAnswer);
                        }
                    }
                    obj.CreatedOn = DateTime.Now;
                    _context.CRM_CommentCardResultsHeader.Add(obj);
                    _context.SaveChanges();


                    // Save the question's answer
                    var commentCardResults = new List <CRM_CommentCardResults>();
                    foreach (var qm in surveyForm.QuestionMaster)
                    {
                        foreach (var que in qm.Questions)
                        {
                            var answer = new CRM_CommentCardResults();
                            answer.CCR_ID         = obj.CCR_ID;
                            answer.q_id           = que.q_id;
                            answer.ctr_answer     = que.userAnswer;
                            answer.ctr_AnswerText = que.options.Where(x => x.Value == que.userAnswer).Select(x => x.Text).FirstOrDefault();
                            answer.q_type         = que.q_type;
                            commentCardResults.Add(answer);
                        }
                    }

                    _context.CRM_CommentCardResults.AddRange(commentCardResults);
                    _context.SaveChanges();
                    dbcxtransaction.Commit();
                    ret = 1;
                }
                catch (Exception ex)
                {
                    dbcxtransaction.Rollback();
                }
            }
            return(ret);
        }