Exemplo n.º 1
0
 public ActionResult AddRole(RoleViewModel item)
 {
     try
     {
         Role r = item.ToModel();
         r.Accesses    = item.GetAccessList(item.Accesses);
         r.Users       = item.GetUserList(item.Users);
         r.CreatedDate = DateTime.Now;
         db.Roles.Add(r);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to insert role " + this.Name + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 2
0
 public ActionResult DeleteSurvey(SurveyViewModel s)
 {
     try
     {
         Survey item = db.Surveys.Find(s.ToModel().Id);
         if (item != null)
         {
             item.DeletionDate = DateTime.Now;
             item.IsDeleted    = true;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete survey from " + this.UserName + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 3
0
 public ActionResult UpdateCountry(CountryViewModel item)
 {
     try
     {
         Country c = db.Countries.Find(item.ToModel().Id);
         if (c != null)
         {
             c.Id             = item.Id;
             c.DeletionDate   = item.DeletionDate;
             c.IsDeleted      = item.IsDeleted;
             c.DeletionUserId = item.DeletionUserId;
             c.ModifiedDate   = DateTime.Now;
             c.ModifiedUserId = item.ModifiedUserId;
             c.Name           = item.Name;
             c.Cities         = item.GetCityList(item.Cities);
             //c.CreatedDate = item.CreatedDate;
             c.CreatedUserId = item.CreatedUserId;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Update",
             Message     = "failed to update country " + this.Name + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 4
0
 public ActionResult DeleteRole(RoleViewModel item)
 {
     try
     {
         Role c = db.Roles.Find(item.ToModel().Id);
         if (c != null)
         {
             c.IsDeleted    = true;
             c.DeletionDate = DateTime.Now;
             foreach (var i in db.Accesses)
             {
                 if (i.RoleId == c.Id)
                 {
                     i.IsDeleted = true;
                 }
             }
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete role " + this.Name + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 5
0
        public ActionResult UpdatePermission(PermissionViewModel item)
        {
            try
            {
                Permission c = db.Permissions.Find(item.ToModel().Id);
                if (c != null)
                {
                    c.Id             = item.Id;
                    c.DeletionDate   = item.DeletionDate;
                    c.DeletionUserId = item.DeletionUserId;
                    c.IsDeleted      = item.IsDeleted;
                    c.ModifiedDate   = DateTime.Now;
                    c.ModifiedUserId = item.ModifiedUserId;
                    c.Name           = item.Name;
                    c.Accesses       = item.GetAccessList(item.Accesses);
                    c.CreatedUserId  = item.CreatedUserId;

                    db.SaveChanges();
                }
                return(new HttpStatusCodeResult(200));
            }
            catch
            {
                LogViewModel l = new LogViewModel
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.Now,
                    Type        = "Update",
                    Message     = "failed to update permission " + this.Name + " to database"
                };
                l.AddLog(l);
                return(new HttpStatusCodeResult(400));
            }
        }
Exemplo n.º 6
0
 public ActionResult DeleteCountry(CountryViewModel item)
 {
     try
     {
         Country c = db.Countries.Find(item.ToModel().Id);
         if (c != null)
         {
             c.IsDeleted    = true;
             c.DeletionDate = DateTime.Now;
             //foreach (var i in db.Cities)
             //{
             //    if (i.CountryId == c.Id)
             //    {
             //        i.IsDeleted = true;
             //    }
             //}
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete country " + this.Name + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 7
0
 public ActionResult DeleteImageType(ImageTypeViewModel item)
 {
     try
     {
         ImageType c = db.ImageTypes.Find(item.ToModel().Id);
         if (c != null)
         {
             c.IsDeleted    = true;
             c.DeletionDate = DateTime.Now;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete image type " + this.Type + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(200));
     }
 }
Exemplo n.º 8
0
        public ActionResult UpdatQuestionType(QuestionTypeViewModel item)
        {
            try
            {
                QuestionType c = db.QuestionTypes.Find(item.ToModel().Id);
                if (c != null)
                {
                    c.Id             = item.Id;
                    c.DeletionDate   = item.DeletionDate;
                    c.IsDeleted      = item.IsDeleted;
                    c.DeletionUserId = item.DeletionUserId;
                    c.ModifiedDate   = DateTime.Now;
                    c.ModifiedUserId = item.ModifiedUserId;
                    c.Questions      = item.GetQuestionList(item.Questions);
                    c.Type           = item.Type;
                    //c.CreatedDate = item.CreatedDate;
                    c.CreatedUserId = item.CreatedUserId;

                    db.SaveChanges();
                }
                return(new HttpStatusCodeResult(200));
            }
            catch
            {
                LogViewModel l = new LogViewModel
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.Now,
                    Type        = "Update",
                    Message     = "failed to update question type " + this.Type + " to database"
                };
                l.AddLog(l);
                return(new HttpStatusCodeResult(400));
            }
        }
Exemplo n.º 9
0
 public ActionResult DeleteSender(NotificationViewModel item)
 {
     try
     {
         Notification c = db.Notifications.Find(item.ToModel().Id);
         if (c != null)
         {
             if (c.ReceiverDeleted == true)
             {
                 c.IsDeleted    = true;
                 c.DeletionDate = DateTime.Now;
             }
             c.SenderDeleted     = true;
             c.SenderDeletedDate = DateTime.Now;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete mail to " + this.ToUsername
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 10
0
 public ActionResult DeleteQuestionAnswer(QuestionAnswerViewModel item)
 {
     try
     {
         QuestionAnswer c = db.QuestionAnswers.Find(item.ToModel().Id);
         if (c != null)
         {
             c.IsDeleted    = true;
             c.DeletionDate = DateTime.Now;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete question answer " + this.Answer + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 11
0
 public ActionResult DeleteAnimate()
 {
     try
     {
         Animate c = db.Animates.Find(this.ToModel().Id);
         if (c != null)
         {
             c.IsDeleted    = true;
             c.DeletionDate = DateTime.Now;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete access to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
 }
Exemplo n.º 12
0
        public ActionResult UpdateUser(UserViewModel item)
        {
            try
            {
                User c = db.Users.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.Birthdate      = item.Birthdate;
                    c.City           = db.Cities.Find(item.CityId);
                    c.CityId         = item.CityId;
                    c.Email          = item.Email;
                    c.FirstName      = item.FirstName;
                    c.Gender         = item.Gender.ToString();
                    c.IsActive       = item.IsActive;
                    c.IsBlocked      = item.IsBlocked;
                    c.IsComplete     = item.IsComplete;
                    c.LastLogin      = item.LastLogin;
                    c.LastName       = item.LastName;
                    c.Password       = item.Password;
                    c.PhoneNumber    = item.PhoneNumber;
                    c.Responses      = item.GetResponseList(item.Responses);
                    c.Role           = db.Roles.Find(item.RoleId);
                    c.RoleId         = item.RoleId;
                    c.Surveys        = item.GetSurveyList(item.Surveys);
                    c.Username       = item.Username;
                    c.CreatedUserId  = item.CreatedUserId;
//                    c.CreatedDate = item.CreatedDate;
                    c.PasswordTokenExpired = item.PasswordTokenExpired;
                    c.PasswordToken        = item.PasswordToken;
                    c.TokenActivated       = item.TokenActivated;
                    db.SaveChanges();
                }
                return(new HttpStatusCodeResult(200));
            }
            catch
            {
                LogViewModel l = new LogViewModel
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.Now,
                    Type        = "Update",
                    Message     = "failed to update user from " + this.CityName + " to database"
                };
                l.AddLog(l);
                return(new HttpStatusCodeResult(400));
            }
        }
Exemplo n.º 13
0
 public ActionResult UpdateSurvey(SurveyViewModel s)
 {
     try
     {
         Survey item = db.Surveys.Find(s.ToModel().Id);
         if (item != null)
         {
             item.IsBlock        = s.IsBlock;
             item.IsDeleted      = s.IsDeleted;
             item.ModifiedDate   = DateTime.Now;
             item.ModifiedUserId = s.ModifiedUserId;
             item.SurveyTypeId   = s.SurveyTypeId;
             item.Title          = s.Title;
             item.DeletionDate   = s.DeletionDate;
             item.DeletionUserId = s.DeletionUserId;
             //item.CreatedDate = s.CreatedDate;
             item.CreatedUserId = s.CreatedUserId;
             item.Description   = s.Description;
             //item.Id = s.Id;
             item.Questions  = s.GetQuestionList(s.Questions);
             item.SurveyType = db.SurveyTypes.Find(s.SurveyTypeId);
             item.User       = db.Users.Find(s.UserId);
             //item.UserId = s.UserId;
             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));
     }
 }
Exemplo n.º 14
0
        public ActionResult UpdateQuestion(QuestionViewModel item)
        {
            try
            {
                Question c = db.Questions.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.Animates        = item.GetAnimateList(item.Animates);
                    c.Content         = item.Content;
                    c.IsFreeText      = item.IsFreeText;
                    c.Number          = item.Number;
                    c.QuestionAnswers = item.GetQuestionAnswerList(item.QuestionAnswers);
                    c.QuestionType    = db.QuestionTypes.Find(item.QuestionTypeId);
                    c.QuestionTypeId  = item.QuestionTypeId;
                    c.Responses       = item.GetResponseList(item.Responses);
                    c.Survey          = db.Surveys.Find(item.SurveyId);
                    c.SurveyId        = item.SurveyId;
                    c.TimeLength      = item.TimeLength;
                    //c.CreatedDate = item.CreatedDate;
                    c.CreatedUserId = item.CreatedUserId;
                    c.Count         = item.Count;
                    c.IsScale       = item.IsScale;
                    c.FontColor     = item.FontColor;
                    c.FontSize      = item.FontSize;

                    db.SaveChanges();
                }
                return(new HttpStatusCodeResult(200));
            }
            catch
            {
                LogViewModel l = new LogViewModel
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.Now,
                    Type        = "Update",
                    Message     = "failed to update question " + this.Content + " to database"
                };
                l.AddLog(l);
                return(new HttpStatusCodeResult(400));
            }
        }
Exemplo n.º 15
0
 public ActionResult DeleteQuestion(QuestionViewModel item)
 {
     try
     {
         Question c = db.Questions.Find(item.ToModel().Id);
         if (c != null)
         {
             c.IsDeleted    = true;
             c.DeletionDate = DateTime.Now;
             foreach (var i in db.Animates)
             {
                 if (i.QuestionId == c.Id)
                 {
                     i.IsDeleted = true;
                 }
             }
             foreach (var i in db.QuestionAnswers)
             {
                 if (i.QuestionId == c.Id)
                 {
                     i.IsDeleted = true;
                 }
             }
             foreach (var i in db.Responses)
             {
                 if (i.QuestionId == c.Id)
                 {
                     i.IsDeleted = true;
                 }
             }
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete question " + this.Content + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 16
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);
     //}
 }
Exemplo n.º 17
0
 public ActionResult AddAnimate()
 {
     try
     {
         Animate a = this.ToModel();
         a.CreatedDate = DateTime.Now;
         db.Animates.Add(a);
         db.SaveChanges();
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     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 animation to database"
         //    };
         //    l.AddLog(l);
         //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
 }
Exemplo n.º 18
0
 public ActionResult UpdateAnimate()
 {
     try
     {
         Animate c = db.Animates.Find(this.ToModel().Id);
         if (c != null)
         {
             c.Id             = this.Id;
             c.IsDeleted      = this.IsDeleted;
             c.ModifiedDate   = DateTime.Now;
             c.ModifiedUserId = this.ModifiedUserId;
             c.DeletionDate   = this.DeletionDate;
             c.DeletionUserId = this.DeletionUserId;
             c.Depth          = this.Depth;
             c.Height         = this.Height;
             c.ImageId        = this.ImageId;
             c.Image          = db.Images.Find(this.ImageId);
             c.PosX           = this.PosX;
             c.PosY           = this.PosY;
             c.Question       = db.Questions.Find(this.QuestionId);
             c.QuestionId     = this.QuestionId;
             c.TimeEnd        = this.TimeEnd;
             c.TimeStart      = this.TimeStart;
             c.Width          = this.Width;
             //c.CreatedDate = this.CreatedDate;
             c.CreatedUserId = this.CreatedUserId;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Update",
             Message     = "failed to update animation to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
 }
Exemplo n.º 19
0
 public ActionResult UpdateImage(ImageViewModel item)
 {
     try
     {
         Image c = db.Images.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;
             item.GetAnimateList(item.Animates, c.Animates);
             c.ImageType = db.ImageTypes.Find(item.ImageTypeId);
             c.Location  = item.Location;
             //c.CreatedDate = item.CreatedDate;
             c.CreatedUserId = item.CreatedUserId;
             c.ImageTypeId   = item.ImageTypeId;
             c.Name          = item.Name;
             c.Name          = item.Name;
             c.Height        = item.Height;
             c.Width         = item.Width;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Update",
             Message     = "failed to update image " + this.Name + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 20
0
 public ActionResult DeleteUser(UserViewModel item)
 {
     try
     {
         User c = db.Users.Find(item.ToModel().Id);
         if (c != null)
         {
             c.IsDeleted    = true;
             c.DeletionDate = DateTime.Now;
             //foreach (var i in db.Responses)
             //{
             //    //if (i.UserId == c.Id)
             //    //{
             //    //    i.IsDeleted = true;
             //    //}
             //}
             foreach (var i in db.Surveys)
             {
                 if (i.UserId == c.Id)
                 {
                     i.IsDeleted = true;
                 }
             }
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Deletion",
             Message     = "failed to delete user from " + this.CityName + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 21
0
 public ActionResult AddQuestionAnswer(QuestionAnswerViewModel item)
 {
     try
     {
         QuestionAnswer q = item.ToModel();
         q.CreatedDate = DateTime.Now;
         db.QuestionAnswers.Add(q);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to insert question answer " + this.Answer + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 22
0
 public ActionResult AddNotification(NotificationViewModel item)
 {
     try
     {
         Notification n = item.ToModel();
         n.CreatedDate = DateTime.Now;
         db.Notifications.Add(n);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to sent mail to " + this.ToUsername
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 23
0
 public ActionResult AddPermission(PermissionViewModel item)
 {
     try
     {
         Permission p = item.ToModel();
         p.CreatedDate = DateTime.Now;
         db.Permissions.Add(p);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to insert permission " + this.Name + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 24
0
 public ActionResult AddImageType(ImageTypeViewModel item)
 {
     try
     {
         ImageType i = item.ToModel();
         i.CreatedDate = DateTime.Now;
         db.ImageTypes.Add(i);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to insert image type " + this.Type + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 25
0
 //ko, kalau pakai actionresult bgmn? Boleh g?
 public ActionResult AddAccess()
 {
     try
     {
         Access a = this.ToModel();
         a.CreatedDate = DateTime.Now;
         db.Accesses.Add(a);
         db.SaveChanges();
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to insert access to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
 }
Exemplo n.º 26
0
 public ActionResult AddSurvey(SurveyViewModel s)
 {
     try
     {
         var item = s.ToModel();
         item.CreatedDate = DateTime.Now;
         db.Surveys.Add(item);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to insert survey from " + this.UserName + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 27
0
 public ActionResult AddCountry(CountryViewModel item)
 {
     try
     {
         Country c = item.ToModel();
         c.Cities = item.GetCityList(item.Cities);
         db.Countries.Add(c);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to insert country " + this.Name + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 28
0
        public ActionResult UpdateQuestionAnswer(QuestionAnswerViewModel item)
        {
            try
            {
                QuestionAnswer c = db.QuestionAnswers.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.Answer         = item.Answer;
                    c.OrderNumber    = item.OrderNumber;
                    c.Question       = db.Questions.Find(item.QuestionId);
                    c.QuestionId     = item.QuestionId;
                    c.CreatedUserId  = item.CreatedUserId;
                    //c.CreatedDate = item.CreatedDate;

                    db.SaveChanges();
                }
                return(new HttpStatusCodeResult(200));
            }
            catch
            {
                LogViewModel l = new LogViewModel
                {
                    Id          = Guid.NewGuid(),
                    CreatedDate = DateTime.Now,
                    Type        = "Update",
                    Message     = "failed to update question answer " + this.Answer + " to database"
                };
                l.AddLog(l);
                return(new HttpStatusCodeResult(400));
            }
        }
Exemplo n.º 29
0
 public ActionResult UpdateAccess()
 {
     try
     {
         Access c = db.Accesses.Find(this.ToModel().Id);
         if (c != null)
         {
             c.Id             = this.Id;
             c.IsDeleted      = this.IsDeleted;
             c.ModifiedDate   = DateTime.Now;
             c.ModifiedUserId = this.ModifiedUserId;
             c.DeletionDate   = this.DeletionDate;
             c.DeletionUserId = this.DeletionUserId;
             c.IsGranted      = this.IsGranted;
             c.Permission     = db.Permissions.Find(this.PermissionId);
             c.PermissionId   = this.PermissionId;
             c.Role           = db.Roles.Find(this.RoleId);
             c.RoleId         = this.RoleId;
             //c.CreatedDate = this.CreatedDate;
             c.CreatedUserId = this.CreatedUserId;
             db.SaveChanges();
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Update",
             Message     = "failed to update access to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
 }
Exemplo n.º 30
0
 public ActionResult AddUser(UserViewModel item)
 {
     try
     {
         User u = item.ToModel();
         u.CreatedDate = DateTime.Now;
         u.LastLogin   = DateTime.Now;
         db.Users.Add(u);
         db.SaveChanges();
         return(new HttpStatusCodeResult(200));
     }
     catch
     {
         LogViewModel l = new LogViewModel
         {
             Id          = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Type        = "Insertion",
             Message     = "failed to insert user from " + this.CityName + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }