コード例 #1
0
ファイル: VolunteerController.cs プロジェクト: nhuang/sms
        public ActionResult Location_Create([DataSourceRequest] DataSourceRequest request, VolunteerLocationModel location)
        {
            int id = 0;
            var session = HttpContext.Session;
            if (session != null)
            {
                if (session["VolunteerId"] != null)
                {
                    id = int.Parse(session["VolunteerId"].ToString());
                }
            }

            if (location != null)
            {
                Location target = new Location();

                if (db.Locations.Where(m => m.locationId == location.locationId).FirstOrDefault() == null)
                {
                    target.volunteerId = id;
                    target.locationType = location.locationType;
                    target.address = location.address;
                    target.city = location.city;
                    target.province = location.province;
                    target.postalcode = stringToUpperCase(location.postalcode);
                    db.Locations.Add(target);
                    db.SaveChanges();
                }
            }
            return Json(ModelState.ToDataSourceResult());
        }
コード例 #2
0
ファイル: VolunteerController.cs プロジェクト: nhuang/sms
        public ActionResult CreateNewLocationForVolunteer(Location model)
        {
            if (model.locationType == "International")
            {
                model.address = convertNullToString(model.address);
                model.city = "";
                model.province = "";
                model.country = "";
                model.postalcode = "";
            }
            else
            {
                model.address = convertNullToString(model.address);
                model.city = stringToTitleCase(convertNullToString(model.city));
                model.province = convertNullToString(model.province);
                model.country = stringToTitleCase(convertNullToString(model.country));
                model.postalcode = convertNullToString(model.postalcode).ToUpper();
            }

            db.Locations.Add(model);
            db.SaveChanges();

            return RedirectToAction("Edit/" + model.volunteerId, "Volunteer");
        }
コード例 #3
0
ファイル: VolunteerController.cs プロジェクト: nhuang/sms
 private void CreateLocation(VolunteerLocationModel model)
 {
     if (model != null)
     {
         Location target = new Location();
         if (db.Locations.Where(m => m.locationId == model.locationId).FirstOrDefault() == null)
         {
             target.volunteerId = model.volunteerId;
             target.locationType = model.locationType;
             target.address = model.address;
             target.city = model.city;
             target.province = model.province;
             target.postalcode = stringToUpperCase(model.postalcode);
             db.Locations.Add(target);
             db.SaveChanges();
         }
     }
 }
コード例 #4
0
ファイル: VolunteerController.cs プロジェクト: nhuang/sms
 public void CreateLocationForNewVolunteer(VolunteerLocationModel model)
 {
     Location location = new Location();
     location.volunteerId = model.volunteerId;
     location.locationType = model.locationType;
     if (model.locationType == "International")
     {
         location.address = convertNullToString(model.address);
         location.city = "";
         location.province = "";
         location.country = "";
         location.postalcode = "";
     }
     else
     {
         location.address = convertNullToString(model.address);
         location.city = stringToTitleCase(convertNullToString(model.city));
         location.province = convertNullToString(model.province);
         location.country = stringToTitleCase(convertNullToString(model.country));
         location.postalcode = convertNullToString(model.postalcode).ToUpper();
     }
     db.Locations.Add(location);
     db.SaveChanges();
 }
コード例 #5
0
ファイル: CSVFileController.cs プロジェクト: nhuang/sms
 private void InsertOrUpateLocation(SmsCsvModel item)
 {
     var v = db.Volunteers.Where(model => model.constituentCode == item.constituentCode);
     if (v.FirstOrDefault() != null)
     {
         Volunteer volunteer = v.FirstOrDefault();
         var location = db.Locations.Where(l => l.volunteerId == volunteer.volunteerId && l.locationType == "Canada");
         if (location.FirstOrDefault() == null)
         {
             // insert into database
             Location newLocation = new Location();
             newLocation.volunteerId = volunteer.volunteerId;
             //contactId=
             newLocation.locationType = "Canada";
             newLocation.address = convertNullToString(item.address);
             newLocation.city = convertNullToString(item.city);
             newLocation.province = convertNullToString(item.province);
             newLocation.postalcode = convertNullToString(item.postalcode);
             db.Locations.Add(newLocation);
             db.SaveChanges();
         }
         else
         {
             Location existLocation = location.FirstOrDefault();
             existLocation.volunteerId = volunteer.volunteerId;
             //contactId=
             existLocation.locationType = "Canada";
             existLocation.address = convertNullToString(item.address);
             existLocation.city = convertNullToString(item.city);
             existLocation.province = convertNullToString(item.province);
             existLocation.postalcode = convertNullToString(item.postalcode);
             db.Entry(existLocation).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
 }