// GET: /RawMaterialQCRedHold/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RawMaterialQCRedHold rawmaterialqcredhold = db.RawMaterialQCRedHolds.Find(id);

            if (rawmaterialqcredhold == null)
            {
                return(HttpNotFound());
            }
            return(View(rawmaterialqcredhold));
        }
        public void DeleteComplete(int id)
        {
            try
            {
                //TPOFormulationRawMaterials handle

                List <int> specificGravityList        = new List <int>();
                List <int> specificGravityDetailsList = new List <int>();

                List <RawMaterialSpecificGravity>       finalSpecificGravitys        = new List <RawMaterialSpecificGravity>();
                List <RawMaterialSpecificGravityDetail> finalSpecificGravitysDetails = new List <RawMaterialSpecificGravityDetail>();
                List <RawMaterialQCRedHold>             finalRedHolds = new List <RawMaterialQCRedHold>();


                List <RawMaterialQC> rawMaterialQCList =
                    _repository.Repository <RawMaterialQC>()
                    .GetAll()
                    .Where(q => q.RawMaterialReceivedID == id)
                    .ToList();

                List <TPOCurrentRawMaterial> tpoCurrentRawMaterialsList =
                    _repository.Repository <TPOCurrentRawMaterial>()
                    .GetAll().Where(q => q.RawMaterialReceivedID == id)
                    .ToList();

                foreach (RawMaterialQC rawMaterialQC in rawMaterialQCList)
                {
                    specificGravityList.Add(rawMaterialQC.ID);
                }

                foreach (int specific in specificGravityList)
                {
                    RawMaterialQCRedHold redholdmodel =
                        _repository.Repository <RawMaterialQCRedHold>()
                        .GetAll()
                        .Where(q => q.RawMaterialQCID == specific && q.RawMaterialReceivedID == id)
                        .ToList()
                        .FirstOrDefault();

                    if (redholdmodel != null)
                    {
                        finalRedHolds.Add(redholdmodel);
                    }

                    RawMaterialSpecificGravity specificGravitymodel =
                        _repository.Repository <RawMaterialSpecificGravity>()
                        .GetAll()
                        .Where(q => q.RawMaterialQCID == specific)
                        .ToList()
                        .FirstOrDefault();

                    if (specificGravitymodel != null)
                    {
                        finalSpecificGravitys.Add(specificGravitymodel);
                    }
                }

                foreach (RawMaterialSpecificGravity specificGravity in finalSpecificGravitys)
                {
                    specificGravityDetailsList.Add(specificGravity.ID);
                }

                foreach (int detail in specificGravityDetailsList)
                {
                    RawMaterialSpecificGravityDetail specificGravityDetailmodel =
                        _repository.Repository <RawMaterialSpecificGravityDetail>()
                        .GetAll()
                        .Where(q => q.RawMaterialSpecGravID == detail)
                        .ToList()
                        .FirstOrDefault();

                    if (specificGravityDetailmodel != null)
                    {
                        finalSpecificGravitysDetails.Add(specificGravityDetailmodel);
                    }
                }

                foreach (RawMaterialSpecificGravityDetail specificGravityDetail in finalSpecificGravitysDetails)
                {
                    Mapper.Map <RawMaterialSpecificGravityDetail, RawMaterialQcSpecificGravityDetailDto>(specificGravityDetail);
                    _repository.Repository <RawMaterialSpecificGravityDetail>().Delete(specificGravityDetail);
                }

                foreach (RawMaterialSpecificGravity specificGravity in finalSpecificGravitys)
                {
                    Mapper.Map <RawMaterialSpecificGravity, RawMaterialSpecificGravityDto>(specificGravity);
                    _repository.Repository <RawMaterialSpecificGravity>().Delete(specificGravity);
                }

                foreach (RawMaterialQCRedHold redhold in finalRedHolds)
                {
                    Mapper.Map <RawMaterialQCRedHold, RawMaterialQcRedHoldDto>(redhold);
                    _repository.Repository <RawMaterialQCRedHold>().Delete(redhold);
                }

                foreach (RawMaterialQC rawMaterialQC in rawMaterialQCList)
                {
                    Mapper.Map <RawMaterialQC, RawMaterialQcDto>(rawMaterialQC);
                    _repository.Repository <RawMaterialQC>().Delete(rawMaterialQC);
                }

                foreach (TPOCurrentRawMaterial tpoCurrentRawMaterial in tpoCurrentRawMaterialsList)
                {
                    Mapper.Map <TPOCurrentRawMaterial, TPOCurrentRawMaterialDto>(tpoCurrentRawMaterial);
                    _repository.Repository <TPOCurrentRawMaterial>().Delete(tpoCurrentRawMaterial);
                }

                _repository.Repository <RawMaterialReceived>().Delete(id);
                _repository.Save();
            }
            catch (DbEntityValidationException valEx)
            {
                var sb = new StringBuilder();

                foreach (var failure in valEx.EntityValidationErrors)
                {
                    sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                    foreach (var error in failure.ValidationErrors)
                    {
                        sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                        sb.AppendLine();
                    }
                }

                throw new DbEntityValidationException(
                          "Entity Validation Failed - errors follow:\n" +
                          sb.ToString(), valEx
                          ); // Add the original exception as the innerException
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw;
            }
        }