Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
0
 public ActionResult UpdateCity(CityViewModel item)
 {
     try
     {
         City c = db.Cities.Find(item.ToModel().Id);
         if (c != null)
         {
             c.Id             = item.Id;
             c.CountryId      = item.CountryId;
             c.Name           = item.Name;
             c.ModifiedDate   = DateTime.Now;
             c.ModifiedUserId = item.ModifiedUserId;
             c.IsDeleted      = item.IsDeleted;
             c.DeletionDate   = item.DeletionDate;
             c.DeletionUserId = item.DeletionUserId;
             c.Users          = item.GetUserList(item.Users);
             c.Country        = db.Countries.Find(c.CountryId);
             //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 city " + this.Name + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 13
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));
     }
 }
Exemplo n.º 14
0
 public ActionResult AddSurveyType(SurveyTypeViewModel item)
 {
     try
     {
         SurveyType c = item.ToModel();
         c.Surveys     = item.GetSurveyList(item.Surveys);
         c.CreatedDate = DateTime.Now;
         db.SurveyTypes.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 survey type " + this.Type + " to database"
         };
         l.AddLog(l);
         return(new HttpStatusCodeResult(400));
     }
 }
Exemplo n.º 15
0
        public ActionResult UpdateImageType(ImageTypeViewModel item)
        {
            try
            {
                ImageType c = db.ImageTypes.Find(item.ToModel().Id);
                if (c != null)
                {
                    //c.Id = item.Id;
                    c.IsDeleted      = item.IsDeleted;
                    c.Images         = item.GetImageList(item.Images);
                    c.ModifiedDate   = DateTime.Now;
                    c.ModifiedUserId = item.ModifiedUserId;
                    c.Type           = item.Type;
                    //c.CreatedDate = item.CreatedDate;
                    c.CreatedUserId = item.CreatedUserId;
                    c.Width         = item.Width;
                    c.Height        = item.Height;
                    //c.DeletionDate = item.DeletionDate;
                    c.DeletionUserId = item.DeletionUserId;
                    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
                    }
                }
                //catch ()
                //{
                //    LogViewModel l = new LogViewModel
                //    {
                //        Id = Guid.NewGuid(),
                //        CreatedDate = DateTime.Now,
                //        Type = "Update",
                //        Message = "failed to update image type " + this.Type + " to database"
                //    };
                //    l.AddLog(l);


                //    return new HttpStatusCodeResult(200);
                //}

                return(new HttpStatusCodeResult(200));
            }
        }