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

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

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "id,asset_id,assetLocation_id,make_id,model_id,productnumber,serialnumber,assetowner,Type,classification_id,warranty,warrantyupto,remarks,lastedit,active")] mouseentry16 mouseentry16)
        {
            if (ModelState.IsValid)
            {
                db.Entry(mouseentry16).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(mouseentry16));
        }
        // GET: /Mouse/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            mouseentry16 mouseentry16 = await db.mouseentry16.FindAsync(id);

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

            if (mouseentry16 == null)
            {
                return(HttpNotFound());
            }
            var mouse = TableMouseEntry();

            return(View(mouse));
        }
        public bool ValidateandInsert(string[] cells)
        {
            mouseentry16 monitor = new mouseentry16();
            int          makeId;
            bool         flag     = false;
            bool         asset_Id = CheckDuplicate("mouseentry16", "asset_id", "S", cells[2].Trim());

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

            if (assetLocation)
            {
                monitor.assetLocation_id = cells[1].Trim();
                flag = true;
            }
            else
            {
                mas_assetLocation al = new mas_assetLocation();
                al.assetLocation = cells[1].Trim();
                al.active        = true;
                db.mas_assetlocation.Add(al);
                db.SaveChanges();
                monitor.assetLocation_id = cells[1].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 = 'MOUSE')");

            if (make)
            {
                makeId          = ReturnId("select Id from mas_make where make = '" + cells[3].Trim() + "' and accessoryId = (select id from mas_accessory where accessory = 'MOUSE')");
                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 == "MOUSE").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 == "MOUSE").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();
            monitor.Type          = cells[7].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() + "'");
                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.mouseentry16.Add(monitor);

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