public async Task <ActionResult> DeleteConfirmed(int id)
        {
            mas_owner mas_owner = await db.mas_owner.FindAsync(id);

            db.mas_owner.Remove(mas_owner);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "id,owner,active")] mas_owner mas_owner)
        {
            if (ModelState.IsValid)
            {
                db.Entry(mas_owner).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(mas_owner));
        }
        public async Task <ActionResult> Create([Bind(Include = "id,owner,active")] mas_owner mas_owner)
        {
            if (ModelState.IsValid)
            {
                db.mas_owner.Add(mas_owner);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(mas_owner));
        }
        // GET: /Owner/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            mas_owner mas_owner = await db.mas_owner.FindAsync(id);

            if (mas_owner == null)
            {
                return(HttpNotFound());
            }
            return(View(mas_owner));
        }
        public bool ValidateandInsert(string[] cells)
        {
            cpuentry16 cpu = new cpuentry16();
            int        makeId;
            bool       flag     = false;
            bool       asset_Id = CheckDuplicate("cpuentry16", "asset_id", "S", cells[1].Trim());

            if (asset_Id)
            {
                return(false);
            }
            else
            {
                cpu.asset_id = cells[1].Trim();
                flag         = true;
            }
            bool assetLocation = CheckDuplicate("mas_assetlocation", "assetLocation", "S", cells[2].Trim());

            if (assetLocation)
            {
                cpu.assetLocation_id = cells[2].Trim();
                flag = true;
            }
            else
            {
                mas_assetLocation al = new mas_assetLocation();
                al.assetLocation = cells[2].Trim();
                al.active        = true;
                db.mas_assetlocation.Add(al);
                db.SaveChanges();
                cpu.assetLocation_id = cells[2].Trim();
            }

            bool make = CheckDuplicate("mas_make", "make", "S", cells[6].Trim());

            if (make)
            {
                makeId      = ReturnId("select Id from mas_make where make = '" + cells[6].Trim() + "'");
                cpu.make_id = makeId;
            }
            else
            {
                mas_make mak = new mas_make();
                mak.make        = cells[6].Trim();
                mak.active      = true;
                mak.accessoryId = 1;
                db.mas_make.Add(mak);
                db.SaveChanges();
                makeId      = mak.id;
                cpu.make_id = makeId;
                flag        = true;
            }
            bool model = CheckDupOnSQLString("select count(id) from mas_model where model='" + cells[3].Trim() + "' and make_id=" + makeId + "");

            if (model)
            {
                int modelId = ReturnId("select Id from mas_model where model= '" + cells[3].Trim() + "'");
                cpu.model_id = modelId;
            }
            else
            {
                mas_model mod = new mas_model();
                mod.accessoryId   = 1;
                mod.make_id       = makeId;
                mod.model         = cells[3].Trim();
                mod.configuration = cells[7].Trim();
                mod.active        = true;
                db.mas_model.Add(mod);
                db.SaveChanges();
                cpu.model_id = mod.id;
                flag         = true;
            }



            cpu.serialnumber  = cells[4].Trim();
            cpu.productnumber = cells[5].Trim();
            String config = cells[7].Replace("\"", "");

            cpu.configuration = config.Trim();

            bool owner = CheckDupOnSQLString("select count(id) from mas_owner where owner='" + cells[8].Trim() + "'");

            if (owner)
            {
                int ownerId = ReturnId("select Id from mas_owner where owner = '" + cells[8].Trim() + "'");
                cpu.assetowner = ownerId;
            }
            else
            {
                mas_owner own = new mas_owner();
                own.owner  = cells[8].Trim();
                own.active = true;
                db.mas_owner.Add(own);
                db.SaveChanges();
                cpu.assetowner = own.id;
                flag           = true;
            }

            bool classfication = CheckDupOnSQLString("select count(id) from mas_classification where classification='" + cells[9].Trim() + "'");

            if (classfication)
            {
                int classification = ReturnId("select Id from mas_classification where classification= '" + cells[9].Trim() + "'");
                cpu.classification_id = classification;
            }
            else
            {
                mas_classification clas = new mas_classification();
                clas.classification = cells[9].Trim();
                clas.active         = true;
                db.mas_classification.Add(clas);
                db.SaveChanges();
                cpu.classification_id = clas.id;
                flag = true;
            }

            bool warty;

            if (cells[10].ToString() == "Yes")
            {
                warty = true;
            }
            else
            {
                warty = false;
            }

            cpu.warranty = warty;
            if (cells[11].Trim() != "NA")
            {
                cpu.warrantyupto = Convert.ToDateTime(cells[11].Trim());
            }
            cpu.remarks  = cells[12].Trim();
            cpu.active   = true;
            cpu.lastedit = DateTime.Now;
            db.cpuentry16.Add(cpu);

            db.SaveChanges();
            return(flag);
        }
        public bool ValidateandInsert(string[] cells)
        {
            monitorentry16 monitor = new monitorentry16();
            int            makeId;
            bool           flag     = false;
            bool           asset_Id = CheckDuplicate("monitorentry16", "asset_id", "S", cells[1].Trim());

            if (asset_Id)
            {
                return(false);
            }
            else
            {
                monitor.asset_id = cells[1].Trim();
                flag             = true;
            }
            bool assetLocation = CheckDuplicate("mas_assetlocation", "assetLocation", "S", cells[2].Trim());

            if (assetLocation)
            {
                monitor.assetLocation_id = cells[2].Trim();
                flag = true;
            }
            else
            {
                mas_assetLocation al = new mas_assetLocation();
                al.assetLocation = cells[2].Trim();
                al.active        = true;
                db.mas_assetlocation.Add(al);
                db.SaveChanges();
                monitor.assetLocation_id = cells[2].Trim();
            }

            //bool asset_Location = CheckDuplicate("monitorentry16", "asset_location", "S", cells[1].Trim());
            //if (asset_Location)
            //{

            //    return false;
            //}
            //else
            //{

            //}
            bool make = CheckDupOnSQLString("select count(Id) from mas_make where make = '" + cells[3].Trim() + "' and accessoryId = (select id from mas_accessory where accessory = 'MONITOR')");

            if (make)
            {
                makeId          = ReturnId("select Id from mas_make where make = '" + cells[3].Trim() + "' and accessoryId = (select id from mas_accessory where accessory = 'MONITOR')");
                monitor.make_id = makeId;

                //Convert.ToInt32(db.mas_make.Where(i => i.make.Contains(cells[6].Trim())).Where(i=>i.accessoryId=).Select(i => i.id).FirstOrDefault());
            }
            else
            {
                mas_make mak = new mas_make();
                mak.make        = cells[3].Trim();
                mak.active      = true;
                mak.accessoryId = Convert.ToInt32(db.mas_Accessory.Where(i => i.accessory == "Monitor").Select(i => i.id).FirstOrDefault());
                db.mas_make.Add(mak);
                db.SaveChanges();
                makeId          = mak.id;
                monitor.make_id = makeId;
                flag            = true;
            }
            bool model = CheckDupOnSQLString("select count(id) from mas_model where model='" + cells[4].Trim() + "' and make_id=" + makeId + "");

            if (model)
            {
                int modelId = ReturnId("select Id from mas_model where model= '" + cells[4].Trim() + "' AND make_id=" + makeId + "");
                monitor.model_id = modelId;
            }
            else
            {
                mas_model mod = new mas_model();
                mod.accessoryId = Convert.ToInt32(db.mas_Accessory.Where(i => i.accessory == "Monitor").Select(i => i.id).FirstOrDefault());
                mod.make_id     = makeId;
                mod.model       = cells[4].Trim();
                //mod.configuration = cells[7].Trim();
                mod.active = true;
                db.mas_model.Add(mod);
                db.SaveChanges();
                monitor.model_id = mod.id;
                flag             = true;
            }



            monitor.serialnumber  = cells[5].Trim();
            monitor.productnumber = cells[6].Trim();

            String config = Regex.Replace(cells[7].Trim(), "[\"|'|,|.]", "");

            monitor.screeninches = float.Parse(config);


            bool owner = CheckDupOnSQLString("select count(id) from mas_owner where owner='" + cells[8].Trim() + "'");

            if (owner)
            {
                int ownerId = ReturnId("select Id from mas_owner where owner = '" + cells[8].Trim() + "'");
                monitor.assetowner = ownerId;
            }
            else
            {
                mas_owner own = new mas_owner();
                own.owner  = cells[8].Trim();
                own.active = true;
                db.mas_owner.Add(own);
                db.SaveChanges();
                monitor.assetowner = own.id;
                flag = true;
            }

            bool classfication = CheckDupOnSQLString("select count(id) from mas_classification where classification='" + cells[9].Trim() + "'");

            if (classfication)
            {
                int classification = ReturnId("select Id from mas_classification where classification= '" + cells[9].Trim() + "'");
                monitor.classification_id = classification;
            }
            else
            {
                mas_classification clas = new mas_classification();
                clas.classification = cells[9].Trim();
                clas.active         = true;
                db.mas_classification.Add(clas);
                db.SaveChanges();
                monitor.classification_id = clas.id;
                flag = true;
            }

            bool warty;

            if (cells[10].ToString() == "Yes")
            {
                warty = true;
            }
            else
            {
                warty = false;
            }

            monitor.warranty = warty;
            //if (cells[11].Trim() != "NA" && cells[11].Trim() != null)
            //{
            //    monitor.warrantyupto = Convert.ToDateTime(cells[11].Trim());
            //}
            monitor.remarks  = cells[11].Trim();
            monitor.active   = true;
            monitor.lastedit = DateTime.Now;
            db.monitorentry16.Add(monitor);

            db.SaveChanges();
            return(flag);
        }