Beispiel #1
0
        public ActionResult Save(UserBuildViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Initialize new instance of the data model
            model.build = (Build)this.Session["SessionBuild"];
            Models.UserBuilds currentLink = new Models.UserBuilds();

            int i = 0;
            int currentBuildID;

            //Dictionary<String, String> buildDictionary = new Dictionary<String, String>();

            //pull i from db

            if (db.Builds.Any((b => b.motherboard_id == model.build.motherboard_id && b.processor_id == model.build.processor_id && b.memory_id == model.build.memory_id && b.hard_drive_id == model.build.hard_drive_id && b.sound_card_id == model.build.sound_card_id && b.video_adapter_id == model.build.video_adapter_id && b.optical_drive_id == model.build.optical_drive_id && b.power_supply_id == model.build.power_supply_id && b.computer_case_id == model.build.computer_case_id)))
            {
                i = db.Builds.Where((b => b.motherboard_id == model.build.motherboard_id && b.processor_id == model.build.processor_id && b.memory_id == model.build.memory_id && b.hard_drive_id == model.build.hard_drive_id && b.sound_card_id == model.build.sound_card_id && b.video_adapter_id == model.build.video_adapter_id && b.optical_drive_id == model.build.optical_drive_id && b.power_supply_id == model.build.power_supply_id && b.computer_case_id == model.build.computer_case_id)).Select(b => b.iterator).SingleOrDefault();
            }

            //Need to add user input to: BuildType, BuildName, BuildTime

            //if i not null update iterator
            if (!(i == 0))
            {
                Build buildQuery = (from b in db.Builds
                                    where b.motherboard_id == model.build.motherboard_id && b.processor_id == model.build.processor_id && b.memory_id == model.build.memory_id && b.hard_drive_id == model.build.hard_drive_id && b.sound_card_id == model.build.sound_card_id && b.video_adapter_id == model.build.video_adapter_id && b.optical_drive_id == model.build.optical_drive_id && b.power_supply_id == model.build.power_supply_id && b.computer_case_id == model.build.computer_case_id
                                    select b).Single <Build>();
                buildQuery.iterator  = i + 1;
                buildQuery.buildType = model.buildType;
                buildQuery.BuildTime = DateTime.Now;
                currentBuildID       = (int)buildQuery.buildID;
            }

            //else add Build with user input
            else
            {
                model.build.iterator  = 1;
                model.build.buildType = model.buildType;
                model.build.BuildTime = DateTime.Now;
                model.build.buildID   = db.Builds.Max(b => b.buildID) + 1;
                db.Builds.Add(model.build);
                currentBuildID = model.build.buildID;
            }

            currentLink.UserId    = User.Identity.GetUserId();
            currentLink.buildName = model.buildName;
            currentLink.buildID   = currentBuildID;

            // Save and redirect
            db.UserBuilds.Add(currentLink);
            db.SaveChanges();

            this.Session["SessionBuild"] = new Build();

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #2
0
        public ActionResult Save(UserBuildViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // Initialize new instance of the data model
            model.build = (Build)this.Session["SessionBuild"];
            Models.UserBuilds currentLink = new Models.UserBuilds();

            int i = 0;
            int currentBuildID;
            //Dictionary<String, String> buildDictionary = new Dictionary<String, String>();

            //pull i from db

            if (db.Builds.Any((b => b.motherboard_id == model.build.motherboard_id && b.processor_id == model.build.processor_id && b.memory_id == model.build.memory_id && b.hard_drive_id == model.build.hard_drive_id && b.sound_card_id == model.build.sound_card_id && b.video_adapter_id == model.build.video_adapter_id && b.optical_drive_id == model.build.optical_drive_id && b.power_supply_id == model.build.power_supply_id && b.computer_case_id == model.build.computer_case_id)))
            {
                i = db.Builds.Where((b => b.motherboard_id == model.build.motherboard_id && b.processor_id == model.build.processor_id && b.memory_id == model.build.memory_id && b.hard_drive_id == model.build.hard_drive_id && b.sound_card_id == model.build.sound_card_id && b.video_adapter_id == model.build.video_adapter_id && b.optical_drive_id == model.build.optical_drive_id && b.power_supply_id == model.build.power_supply_id && b.computer_case_id == model.build.computer_case_id)).Select(b => b.iterator).SingleOrDefault();
            }

            //Need to add user input to: BuildType, BuildName, BuildTime

            //if i not null update iterator
            if (!(i == 0))
            {
                Build buildQuery = (from b in db.Builds
                                    where b.motherboard_id == model.build.motherboard_id && b.processor_id == model.build.processor_id && b.memory_id == model.build.memory_id && b.hard_drive_id == model.build.hard_drive_id && b.sound_card_id == model.build.sound_card_id && b.video_adapter_id == model.build.video_adapter_id && b.optical_drive_id == model.build.optical_drive_id && b.power_supply_id == model.build.power_supply_id && b.computer_case_id == model.build.computer_case_id
                                    select b).Single<Build>();
                buildQuery.iterator = i + 1;
                buildQuery.buildType = model.buildType;
                buildQuery.BuildTime = DateTime.Now;
                currentBuildID = (int)buildQuery.buildID;
            }

            //else add Build with user input
            else
            {
                model.build.iterator = 1;
                model.build.buildType = model.buildType;
                model.build.BuildTime = DateTime.Now;
                model.build.buildID = db.Builds.Max(b => b.buildID) + 1;
                db.Builds.Add(model.build);
                currentBuildID = model.build.buildID;
            }

            currentLink.UserId = User.Identity.GetUserId();
            currentLink.buildName = model.buildName;
            currentLink.buildID = currentBuildID;

            // Save and redirect
            db.UserBuilds.Add(currentLink);
            db.SaveChanges();

            this.Session["SessionBuild"] = new Build();

            return RedirectToAction("Index", "Home");
        }