Example #1
0
        public ActionResult UpdateRespondent(RespondentViewModel item)
        {
            try
            {
                Respondent c = db.Respondents.Find(item.ToModel().Id);
                if (c != null)
                {
                    c.Id             = item.Id;
                    c.IsDeleted      = item.IsDeleted;
                    c.ModifiedDate   = DateTime.Now;
                    c.ModifiedUserId = item.ModifiedUserId;
                    c.DeletionDate   = item.DeletionDate;
                    c.DeletionUserId = item.DeletionUserId;
                    c.BrowserName    = item.BrowserName;
                    c.IPAdress       = item.IPAdress;
                    c.IsDeleted      = item.IsDeleted;
                    c.IsRegistered   = item.IsRegistered;
                    c.CreatedUserId  = item.CreatedUserId;
                    c.SurveyId       = item.SurveyId;
                    c.UserId         = item.UserId;

                    db.SaveChanges();
                }
                return(new HttpStatusCodeResult(200));
            }
            catch
            {
                return(new HttpStatusCodeResult(400));
            }
        }
Example #2
0
 public ActionResult AddRespondent(RespondentViewModel item)
 {
     try
     {
         Respondent r = item.ToModel();
         r.CreatedDate = DateTime.Now;
         db.Respondents.Add(r);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
     {
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 string message = string.Format("{0}:{1}",
                                                validationErrors.Entry.Entity.ToString(),
                                                validationError.ErrorMessage);
                 LogViewModel l = new LogViewModel
                 {
                     Id          = Guid.NewGuid(),
                     CreatedDate = DateTime.Now,
                     Type        = "Update",
                     Message     = message
                 };
                 l.AddLog(l);
                 db.SaveChanges();
                 // raise a new exception nesting
                 // the current instance as InnerException
             }
         }
         return(new HttpStatusCodeResult(400));
     }
     //catch
     //{
     //    LogViewModel l = new LogViewModel
     //    {
     //        Id = Guid.NewGuid(),
     //        CreatedDate = DateTime.Now,
     //        Type = "Insertion",
     //        Message = "failed to insert response from" + this.IPAdress + " to database"
     //    };
     //    l.AddLog(l);
     //    return new HttpStatusCodeResult(400);
     //}
 }
Example #3
0
 public ActionResult DeleteRespondent(RespondentViewModel item)
 {
     try
     {
         Respondent c = db.Respondents.Find(item.ToModel().Id);
         if (c != null)
         {
             c.IsDeleted    = true;
             c.DeletionDate = DateTime.Now;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         return(new HttpStatusCodeResult(400));
     }
 }