Esempio n. 1
0
        //[ValidateAntiForgeryToken]
        public async Task<ActionResult> Create(newProjectModels model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    NewProject newProject = new NewProject()
                    {
                        AnalysisUrl = Utilities.saveFile(Request.Files["AnalysisUrl"], model.ProjectName + "\\Analysis"),
                        ApplicationsId = model.ApplicationsId,
                        ArchitectId = model.ArchitectId,
                        AreaPanelCalculationUrl = Utilities.saveFile(Request.Files["AreaPanelCalculationUrl"], model.ProjectName + "\\AreaPanelCalculation"),
                        BOQUrl = Utilities.saveFile(Request.Files["BOQUrl"], model.ProjectName + "\\BOQ"),
                        BusinessPartnerId = model.BusinessPartnerId,
                        City = model.City,
                        CommencedOn = model.CommencedOn.ToShortDateString(),
                        ConceptsDrawingUrl = Utilities.saveFile(Request.Files["ConceptsDrawingUrl"], model.ProjectName + "\\ConceptsDrawing"),
                        ConcludedOn = model.ConcludedOn.ToShortDateString(),
                        ElevationsUrl = Utilities.saveFile(Request.Files["ElevationsUrl"], model.ProjectName + "\\Elevations"),
                        FixingTypeId = model.FixingTypeId,
                        InteriorUrl = Utilities.saveFile(Request.Files["InteriorUrl"], model.ProjectName + "\\Interior"),
                        OptimizationUrl = Utilities.saveFile(Request.Files["OptimizationUrl"], model.ProjectName + "\\Optimization"),
                        OwnerId = model.OwnerId,
                        PlanUrl = Utilities.saveFile(Request.Files["PlanUrl"], model.ProjectName + "\\Plan"),
                        ProjectName = model.ProjectName,
                        ProjectTypeId = model.ProjectTypeId,
                        SectionsUrl = Utilities.saveFile(Request.Files["SectionsUrl"], model.ProjectName + "\\Sections"),
                        ShopDrawingUrl = Utilities.saveFile(Request.Files["ShopDrawingUrl"], model.ProjectName + "\\ShopDrawing"),
                        Street = model.Street,
                        TDImageUrl = Utilities.saveFile(Request.Files["TDImageUrl"], model.ProjectName + "\\TDImage"),
                        TDRenderImageUrl = Utilities.saveFile(Request.Files["TDRenderImageUrl"], model.ProjectName + "\\TDRenderImage")
                    };
                    db.NewProjects.Add(newProject);
                    await db.SaveChangesAsync();
                    ViewBag.ApplicationsId = new SelectList(db.Applications, "Id", "Name", newProject.ApplicationsId);
                    ViewBag.ArchitectId = new SelectList(db.Architects, "Id", "FullName", newProject.ArchitectId);
                    ViewBag.BusinessPartnerId = new SelectList(db.BusinessPartners, "Id", "FullName", newProject.BusinessPartnerId);
                    ViewBag.FixingTypeId = new SelectList(db.FixingTypes, "Id", "Name", newProject.FixingTypeId);
                    ViewBag.OwnerId = new SelectList(db.Owners, "Id", "FullName", newProject.OwnerId);
                    ViewBag.ProjectTypeId = new SelectList(db.ProjectTypes, "Id", "Name", newProject.ProjectTypeId);

                    return RedirectToAction("Index");

                }
            }
            catch (Exception ex)
            {
                if (ex is DbEntityValidationException)
                {
                    foreach (var validationErrors in ((DbEntityValidationException)ex).EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                    //return InternalServerError();
                }

            }
            return RedirectToAction("Index");

            //return View(newProject);
        }
Esempio n. 2
0
        public async Task<ActionResult> Edit(newProjectModels model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(model).State = EntityState.Modified;
                    await db.SaveChangesAsync();
                    return RedirectToAction("Index");
                }

            }
            catch (Exception ex)
            {
                if (ex is DbEntityValidationException)
                {
                    foreach (var validationErrors in ((DbEntityValidationException)ex).EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                    //return InternalServerError();
                }

            }
        ViewBag.ApplicationsId = new SelectList(db.Applications, "Id", "Name", model.ApplicationsId);
            ViewBag.ArchitectId = new SelectList(db.Architects, "Id", "FullName", model.ArchitectId);
            ViewBag.BusinessPartnerId = new SelectList(db.BusinessPartners, "Id", "FullName", model.BusinessPartnerId);
            ViewBag.FixingTypeId = new SelectList(db.FixingTypes, "Id", "Name", model.FixingTypeId);
            ViewBag.OwnerId = new SelectList(db.Owners, "Id", "FullName", model.OwnerId);
            ViewBag.ProjectTypeId = new SelectList(db.ProjectTypes, "Id", "Name", model.ProjectTypeId);
            return View(model);
        }