示例#1
0
        public ResponseModel <ExamStatusModel> Delete(int id)
        {
            ResponseModel <ExamStatusModel> result = new ResponseModel <ExamStatusModel> {
                Data = new ExamStatusModel()
            };

            try
            {
                var item = _context.ExamStatuses.Include("ExamDetails").Where(e => e.Id == id).Select(e => e).FirstOrDefault();
                if (item != null)
                {
                    //_context.ExamStatuses.Remove(item);
                    item.IsActive = false;
                    _context.SaveChanges();
                    result.status  = true;
                    result.message = "Success";
                }
                else
                {
                    result.status  = false;
                    result.message = "Status Not Found";
                }
            }
            catch (Exception ex)
            {
                result.message = ex.Message;
            }
            return(result);
        }
示例#2
0
        public ResponseModel <ExamModel> Save(ExamModel model)
        {
            ResponseModel <ExamModel> result = new ResponseModel <ExamModel> {
                Data = new ExamModel()
            };

            try
            {
                Exams db = new Exams();
                db.TestTitle            = model.TestTitle;
                db.CreatedOn            = DateTime.Now;
                db.IsAttachmentRequired = model.IsAttachmentRequired;
                db.IsActive             = true;
                db.LastUpdatedBy        = model.LastUpdatedBy;
                db.LastUpdatedOn        = model.LastUpdatedOn;
                _context.Exams.Add(db);
                _context.SaveChanges();
                result = new ResponseModel <ExamModel> {
                    status = true, message = "Success", Data = new ExamModel()
                    {
                        TestId = db.TestId, TestTitle = db.TestTitle
                    }
                };
            }
            catch (Exception ex)
            {
                result.status  = false;
                result.message = ex.Message;
                result.Data    = new ExamModel()
                {
                    TestId = 0, TestTitle = null
                };
            }
            return(result);
        }
示例#3
0
        public ResponseModel <ExamQuestionModel> Save(List <QuestionsList> modelList, long TestId)
        {
            ResponseModel <ExamQuestionModel> result = new ResponseModel <ExamQuestionModel> {
                Data = new ExamQuestionModel()
            };

            try
            {
                foreach (var model in modelList)
                {
                    ExamQuestions db = new ExamQuestions();
                    db.ExamId    = TestId;
                    db.Question  = model.Name;
                    db.CreatedOn = DateTime.Now;
                    db.IsActive  = true;
                    _context.ExamQuestions.Add(db);
                }
                modelList = null;
                _context.SaveChanges();
                result = new ResponseModel <ExamQuestionModel> {
                    status = true, message = "Success"
                };
            }
            catch (Exception ex)
            {
                result.status  = false;
                result.message = ex.Message;
            }
            return(result);
        }
示例#4
0
        public ResponseModel <string> Office365SignUp(IDictionary <string, string> data)
        {
            string email = string.Empty;

            if (data.ContainsKey("email"))
            {
                email = data["email"];
            }
            else if (data.ContainsKey("upn"))
            {
                email = data["upn"];
            }

            if (string.IsNullOrWhiteSpace(email))
            {
                return(new ResponseModel <string> {
                    message = "Invalid email! Cannot register account at the moment."
                });
            }

            var userProfile = _context.UserProfile.FirstOrDefault(x => x.Email == email);

            if (userProfile == null)
            {
                Random rnd = new Random();
                Int64  i64 = rnd.Next(10000000, 99999999);
                i64 = (i64 * 100000000) + rnd.Next(0, 999999999);
                var         result  = Math.Abs(i64).ToString();
                UserProfile profile = new UserProfile
                {
                    Id        = Convert.ToInt64(result),
                    Email     = email,
                    FirstName = data.ContainsKey("given_name") == true ? data["given_name"] : data["name"],
                    LastName  = data.ContainsKey("family_name") == true ? data["family_name"] : string.Empty,
                    Gender    = "male"
                };
                _context.UserProfile.Add(profile);
                _context.SaveChanges();
                AppUtilities.SetCookiesData(new Office365Model
                {
                    GivenName         = data.ContainsKey("given_name") == true ? data["given_name"] : data["name"],
                    UserPrincipalName = data["email"],
                    Surname           = data.ContainsKey("family_name") == true ? data["family_name"] : string.Empty
                });
                return(new ResponseModel <string> {
                    status = true, message = "Success", Data = ""
                });
            }
            else
            {
                return(new ResponseModel <string> {
                    message = "User already registered."
                });
            }
        }
        /// <summary>
        /// Get the testdetails and save the startdate, time and status in exam details
        /// </summary>
        /// <param name="examdetailId"></param>
        /// <returns></returns>
        public ResponseModel <TestModel> GetTestDetails(int examdetailId)
        {
            ResponseModel <TestModel> result = new ResponseModel <TestModel>();

            try
            {
                var examDetailModels = _context.ExamDetails.Include("ExamSesson").Where(e => e.Id == examdetailId && e.UniqueId != null).Select(e => e).FirstOrDefault();
                if (examDetailModels != null)
                {
                    if (examDetailModels.Startdate == null && examDetailModels.Starttime == null && examDetailModels.Status == null)
                    {
                        examDetailModels.Startdate = DateTime.Now;
                        examDetailModels.Starttime = DateTime.Now.TimeOfDay;
                        examDetailModels.Status    = false;
                        _context.SaveChanges();
                    }
                    if (examDetailModels.ExamSesson != null && examDetailModels.ExamSesson.TestId != null)
                    {
                        _context.Exams.ToList();
                        _context.ExamQuestions.ToList();
                        result.Data = new TestModel
                        {
                            Id           = Convert.ToString(examDetailModels.ExamSesson.TestId),
                            TestName     = examDetailModels?.ExamSesson?.Test?.TestTitle,
                            IsAttachment = Convert.ToBoolean(examDetailModels?.ExamSesson?.Test?.IsAttachmentRequired),
                            Questions    = examDetailModels.ExamSesson.Test.ExamQuestions.Where(x => x.IsActive == true).Select(e => new QuestionsList {
                                Id = e.QuestionId, Name = e.Question
                            }).ToList()
                        };
                    }
                    else
                    {
                        result.Data = new TestModel();
                    }
                    result.status  = true;
                    result.message = examDetailModels.UniqueId;
                }
                else
                {
                    result.status  = false;
                    result.message = "Test does not exists";
                }
            }
            catch (Exception ex)
            {
                result.message = ex.Message;
            }

            return(result);
        }
示例#6
0
        public ResponseModel <ExamAnswerModel> Save(List <QuestionsList> modelList, int?ExamDetailId)
        {
            ResponseModel <ExamAnswerModel> result = new ResponseModel <ExamAnswerModel> {
                Data = new ExamAnswerModel()
            };

            try
            {
                // foreach (var model in modelList.Where(x => !String.IsNullOrWhiteSpace(x.Name)).ToList())
                foreach (var model in modelList)
                {
                    ExamQuestionAnswer db = new ExamQuestionAnswer();
                    db.ExamDetailId = ExamDetailId;
                    db.Answer       = model.Name;
                    db.CreatedOn    = DateTime.Now;
                    db.QuestionId   = model.Id;
                    _context.ExamQuestionAnswer.Add(db);
                }
                modelList = null;
                _context.SaveChanges();
                result = new ResponseModel <ExamAnswerModel> {
                    status = true, message = "Success"
                };
            }
            catch (Exception ex)
            {
                result.status  = false;
                result.message = ex.Message;
            }
            return(result);
        }
        /// <summary>
        /// save and update test session
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResponseModel <CreateSessionModel> Save(CreateSessionModel model)
        {
            ResponseModel <CreateSessionModel> result = new ResponseModel <CreateSessionModel> {
                Data = new CreateSessionModel()
            };

            try
            {
                Guid obj     = Guid.NewGuid();
                var  _exists = _context.ExamSessions.Where(x => x.EmailAddress == model.Email).FirstOrDefault();
                if (_exists == null)
                {
                    ExamSessions db = new ExamSessions();
                    db.Firstname    = model.FirstName;
                    db.Lastname     = model.LastName;
                    db.Notes        = model.Notes;
                    db.EmailAddress = model.Email;
                    db.Createdate   = DateTime.Now;
                    db.SourceId     = Convert.ToInt32(model.Source);
                    db.TestId       = Convert.ToInt64(model.TestId);
                    _context.ExamSessions.Add(db);
                    _context.SaveChanges();
                    SendAccessMail(model, obj, null, db.Id);
                }
                else
                {
                    _exists.Modifydate    = DateTime.Now;
                    _exists.Firstname     = model.FirstName;
                    _exists.Lastname      = model.LastName;
                    _exists.Notes         = model.Notes;
                    _exists.SourceId      = Convert.ToInt32(model.Source);
                    _exists.SessionCounts = _exists.SessionCounts == null ? 1 : _exists.SessionCounts + 1;
                    _exists.TestId        = Convert.ToInt64(model.TestId);
                    _context.ExamSessions.Attach(_exists);
                    _context.Entry(_exists).State = EntityState.Modified;
                    _context.SaveChanges();
                    SendAccessMail(model, obj, null, _exists.Id);
                }

                result.status  = true;
                result.message = obj.ToString();
            }
            catch (Exception ex)
            {
                result.message = ex.Message;
            }

            return(result);
        }