Ejemplo n.º 1
0
        public ActionResult AddConcreteSample(ConcreteSamplesWithPath sample)
        {
            ObjectParameter statusCode    = new ObjectParameter("StatusCode", typeof(int));
            ObjectParameter statusMessage = new ObjectParameter("StatusMessage", typeof(string));


            if (sample.ConcreteTemperture >= 34 || sample.DownAmount <= 100)
            {
                bool       Flag  = false;
                Infraction infra = db.Infractions.Where(s => s.SampleNo == sample.SampleNumber).FirstOrDefault();
                if (infra == null)
                {
                    Flag  = true;
                    infra = new Infraction();
                    infra.AdminApproved   = false;
                    infra.MonitorApproved = false;
                    infra.VisitDate       = DateTime.Now;
                }
                //infra.FactoryId = sample.FactoryId;
                infra.SampleNo = sample.SampleNumber;
                if (sample.ConcreteTemperture >= 34)
                {
                    infra.Temperature = true;
                }
                if (sample.DownAmount <= 100)
                {
                    infra.Landing = true;
                }
                if (sample.IsCleanLocation == false)
                {
                    infra.IsCleanLocation = false;
                }
                if (Flag == true)
                {
                    db.Infractions.Add(infra);
                }
                db.SaveChanges();
            }

            foreach (var file in sample.files)
            {
                if (file != null)
                {
                    Random   random         = new Random();
                    FileInfo fi             = new FileInfo(file.FileName);
                    DateTime d              = DateTime.Now;
                    var      InputFileName  = d.Ticks + random.Next(100, 100000000).ToString();
                    var      ServerSavePath = System.IO.Path.Combine(Server.MapPath("~/Content"), InputFileName + fi.Extension);
                    //Save file to server folder
                    file.SaveAs(ServerSavePath);
                    sample.InvoicePhoto = InputFileName + fi.Extension;
                }
            }
            foreach (var file in sample.CleanDocfiles)
            {
                if (file != null)
                {
                    Random   random = new Random();
                    FileInfo fi     = new FileInfo(file.FileName);

                    DateTime d              = DateTime.Now;
                    var      InputFileName  = d.Ticks + random.Next(100, 100000000).ToString();
                    var      ServerSavePath = System.IO.Path.Combine(Server.MapPath("~/Content"), InputFileName + fi.Extension);
                    //Save file to server folder
                    file.SaveAs(ServerSavePath);
                    sample.CleanDocPath = InputFileName + fi.Extension;
                }
            }
            foreach (var file in sample.DustDocfiles)
            {
                if (file != null)
                {
                    Random   random         = new Random();
                    FileInfo fi             = new FileInfo(file.FileName);
                    DateTime d              = DateTime.Now;
                    var      InputFileName  = d.Ticks + random.Next(100, 100000000).ToString();
                    var      ServerSavePath = System.IO.Path.Combine(Server.MapPath("~/Content"), InputFileName + fi.Extension);
                    //Save file to server folder
                    file.SaveAs(ServerSavePath);
                    sample.DustDocPath = InputFileName + fi.Extension;
                }
            }
            foreach (var file in sample.LabDocfiles)
            {
                if (file != null)
                {
                    Random   random         = new Random();
                    FileInfo fi             = new FileInfo(file.FileName);
                    DateTime d              = DateTime.Now;
                    var      InputFileName  = d.Ticks + random.Next(100, 100000000).ToString();
                    var      ServerSavePath = System.IO.Path.Combine(Server.MapPath("~/Content"), InputFileName + fi.Extension);
                    //Save file to server folder
                    file.SaveAs(ServerSavePath);
                    sample.LabDocPath = InputFileName + fi.Extension;
                }
            }
            foreach (var file in sample.SafteyDocfiles)
            {
                if (file != null)
                {
                    Random   random         = new Random();
                    FileInfo fi             = new FileInfo(file.FileName);
                    DateTime d              = DateTime.Now;
                    var      InputFileName  = d.Ticks + random.Next(100, 100000000).ToString();
                    var      ServerSavePath = System.IO.Path.Combine(Server.MapPath("~/Content"), InputFileName + fi.Extension);
                    //Save file to server folder
                    file.SaveAs(ServerSavePath);
                    sample.SafteyDocPath = InputFileName + fi.Extension;
                }
            }
            foreach (var file in sample.SummerDocfiles)
            {
                if (file != null)
                {
                    Random   random         = new Random();
                    FileInfo fi             = new FileInfo(file.FileName);
                    DateTime d              = DateTime.Now;
                    var      InputFileName  = d.Ticks + random.Next(100, 100000000).ToString();
                    var      ServerSavePath = System.IO.Path.Combine(Server.MapPath("~/Content"), InputFileName + fi.Extension);
                    //Save file to server folder
                    file.SaveAs(ServerSavePath);
                    sample.SummerDocPath = InputFileName + fi.Extension;
                }
            }
            foreach (var file in sample.TruckDocfiles)
            {
                if (file != null)
                {
                    Random   random         = new Random();
                    FileInfo fi             = new FileInfo(file.FileName);
                    DateTime d              = DateTime.Now;
                    var      InputFileName  = d.Ticks + random.Next(100, 100000000).ToString();
                    var      ServerSavePath = System.IO.Path.Combine(Server.MapPath("~/Content"), InputFileName + fi.Extension);
                    //Save file to server folder
                    file.SaveAs(ServerSavePath);
                    sample.TruckDocPath = InputFileName + fi.Extension;
                }
            }
            if (sample.Reason1 == null)
            {
                sample.OtherReason = sample.Reason2;
            }
            else
            {
                sample.OtherReason = sample.Reason1;
            }

            var uId = Convert.ToInt32(Session["UserId"].ToString());

            db.AddUpdateConcreteSample(sample.ReportNo, sample.ReportDate, sample.FactoryName, sample.FactoryLocation, sample.MixerNumber, sample.VisitNumber,
                                       sample.SampleNumber, sample.TruckNumber, sample.InvoiceNumber, sample.ClientName, sample.VisitLocation, sample.Latitude,
                                       sample.Longitude, sample.ConcreteRank, sample.ConcreteTemperture, sample.WaterTemperature, sample.WeatherTemperture,
                                       sample.DownAmount, sample.CementType, sample.CementSource, sample.AdditionType, sample.AdditionAmount, sample.CementWeight,
                                       sample.WaterWieght, sample.WashedSandWeight, sample.WhiteSandWeight, sample.Rubble3by4, sample.Rubble3by8, sample.IsCleanUsage,
                                       sample.IsBasicUsage, sample.IsColumnUsage, sample.IsRoofUsage, sample.IsOtherUsage, sample.IsCleanLocation, sample.CleanDocPath,
                                       sample.IsDustControlInStation, sample.DustDocPath, sample.IsRokamSummer, sample.SummerDocPath, sample.IsLabEngineer, sample.LabDocPath,
                                       sample.IsMoldanatInTrucks, sample.TruckDocPath, sample.IsPeopleSafty, sample.SafteyDocPath, uId, null, statusCode, statusMessage, sample.InvoicePhoto
                                       , sample.CleanDocNote, sample.DustDocNote, sample.SummerDocNote, sample.LabDocNote, sample.TruckDocNote, sample.SafteyDocNote, sample.OtherReason);

            TempData["AlertMessage1"] = "Success";
            return(RedirectToAction("Home", "Home", new { Id = 1 }));
        }