示例#1
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));
     }
 }
示例#2
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));
     }
 }