예제 #1
0
		public void Destroy(CarMakeViewModel carMake)
		{
			var make = new CarMake ( );

			make.MakeId = carMake.MakeId;

			_context.CarMakes.Attach ( make );

			_context.CarMakes.Remove ( make );

			_context.SaveChanges ( );
		}
예제 #2
0
		public void Create (CarMakeViewModel carMake)
		{
			var make = new CarMake ( );

			make.MakeTitle = carMake.MakeTitle;
			make.BrandLogoUrl = carMake.BrandLogoUrl;
			make.OriginId = carMake.OriginId;

			_context.CarMakes.Add ( make );
			_context.SaveChanges ( );

			carMake.MakeId = make.MakeId;
		}
        public ActionResult UpdateCarMake ( [DataSourceRequest] DataSourceRequest request, CarMakeViewModel make )
        {
			CarMake carMake = db.CarMakes.Where ( m => m.MakeId == make.MakeId ).FirstOrDefault ( );

			ViewData [ "CarMakeOrigins" ] = from origin in db.CarMakeOrigins.Distinct ( )
											select new
											{
												origin.OriginId,
												origin.OriginTitle
											};
			ViewData [ "DefaultOrigin" ] = db.CarMakeOrigins.First ( );

			if ( make != null && ModelState.IsValid )
            {
				carMake.MakeTitle = make.MakeTitle;
				carMake.OriginId = make.OriginId;

				carMake.CarMakeOrigin = db.CarMakeOrigins.Where ( o => o.OriginId == make.OriginId ).FirstOrDefault ( );
				make.CarMakeOrigin = carMake.CarMakeOrigin;

				try
				{
					db.CarMakes.Attach ( carMake );
					db.Entry ( carMake ).State = EntityState.Modified;
					db.SaveChanges ( );
				}
				catch ( DbEntityValidationException ex)
				{
					Debug.WriteLine ( "[Car Make Module] DbEntityValidationException Caught" );
					Debug.WriteLine ( "----------------------------------------------------" );
					var errorMessages = ex.EntityValidationErrors.SelectMany ( x => x.ValidationErrors ).Select ( x => x.ErrorMessage );

					var fullErrorMessage = string.Join ( ";\n", errorMessages );

					var exceptionMessage = string.Concat ( ex.Message, "The validation errors are: ", fullErrorMessage );

					Debug.WriteLine ( exceptionMessage );
				}
            }

			Debug.WriteLine ( "[Car Make Module] Record values:" );
			Debug.WriteLine ( "{" );
			Debug.WriteLine ( "\tMakeId : " + make.MakeId.ToString ( ) );
			Debug.WriteLine ( "\tOriginId : " + make.OriginId.ToString ( ) );
			Debug.WriteLine ( "\tMakeTitle : " + make.MakeTitle );
			Debug.WriteLine ( "\tOriginTitle : " + make.CarMakeOrigin.OriginTitle );
			Debug.WriteLine ( "\tBrandLogoUrl : " + make.BrandLogoUrl );
			Debug.WriteLine ( "}" );

			return Json ( new [ ] { make }.ToDataSourceResult ( request, ModelState ) );
        }
예제 #4
0
		public void Update (CarMakeViewModel carMake)
		{
			var make = new CarMake ( );

			make.MakeId = carMake.MakeId;
			make.OriginId = carMake.OriginId;
			make.MakeTitle = carMake.MakeTitle;

			if (carMake.BrandLogoUrl != null)
			{
				make.BrandLogoUrl = carMake.BrandLogoUrl;
			}

			if (carMake.CarMakeOrigin != null)
			{
				make.OriginId = carMake.CarMakeOrigin.OriginId;
			}

			_context.CarMakes.Attach ( make );
			_context.Entry ( make ).State = EntityState.Modified;
			_context.SaveChanges ( );
		}