// GET: Trasach/Edit/5
 public ActionResult Edit(int id)
 {
     using (ModelDbContext modelDbContext = new ModelDbContext())
     {
         return(View(modelDbContext.TRASACHes.Where(x => x.MATRASACH == id).FirstOrDefault()));
     }
 }
Exemplo n.º 2
0
        public override void Delete(ModelDbContext context)
        {
            context.Warlocks.Remove(context.Warlocks.SingleOrDefault(c => c.ID == this.ID));


            var soloAbils = (context.WarlockAbillities.Where(c => c.WarlockId == ID));

            foreach (var abil in soloAbils)
            {
                context.WarlockAbillities.Remove(abil);
            }



            var soloSpells = (context.WarlockSpells.Where(c => c.WarlockId == ID));

            foreach (var spell in soloSpells)
            {
                context.WarlockSpells.Remove(spell);
            }

            var soloWeaps = (context.WarlockWeapons.Where(c => c.WarlockId == ID));

            foreach (var weap in soloWeaps)
            {
                context.WarlockWeapons.Remove(weap);
            }

            context.SaveChanges();
        }
 public IEnumerable <Employee> Get()
 {
     using (ModelDbContext db = new ModelDbContext())
     {
         return(db.Employees.ToList());
     }
 }
Exemplo n.º 4
0
 public bool IsUserName(string userName)
 {
     using (ModelDbContext db = new ModelDbContext())
     {
         return(db.tblUsers.Any(p => p.UserName.Equals(userName) || p.UserName.ToUpper().Equals(userName.ToUpper())));
     }
 }
Exemplo n.º 5
0
 public tblUser GetByEmail(string email)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblUsers.SingleOrDefault(p => p.Email.ToLower().Equals(email.ToLower().Trim())));
     }
 }
Exemplo n.º 6
0
 public ICollection <tblUser> GetByPaging(int pageNumber, int pageSize)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblUsers.Where(p => p.Status != (short)Commons.Status.Deleted).OrderByDescending(p => p.Id).Skip(pageNumber * pageSize).Take(pageNumber).ToList());
     }
 }
Exemplo n.º 7
0
 public IPagedList <tblUser> GetByPageList(int pageNumber, int pageSize)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblUsers.Where(p => p.Status != (short)Commons.Status.Deleted).OrderByDescending(p => p.Id).ToPagedList(pageNumber, pageSize));
     }
 }
Exemplo n.º 8
0
        //添加字段
        public static void AddField(this ModelDbContext context, RuntimeModelMeta model, RuntimeModelMeta.ModelPropertyMeta property)
        {
            using (DbConnection conn = context.Database.GetDbConnection())
            {
                if (conn.State != System.Data.ConnectionState.Open)
                {
                    conn.Open();
                }

                DbCommand addFieldCmd = conn.CreateCommand();
                addFieldCmd.CommandText = $"alert table {model.ClassName} add {property.PropertyName} ";

                switch (property.ValueType)
                {
                case "int":
                    addFieldCmd.CommandText += "int";
                    break;

                case "datetime":
                    addFieldCmd.CommandText += "datetime";
                    break;

                case "bool":
                    addFieldCmd.CommandText += "bit";
                    break;

                default:
                    addFieldCmd.CommandText += "nvarchar(max)";
                    break;
                }

                addFieldCmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 9
0
 public ICollection <tblComment> GetByNews(int id)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblComments.Where(p => p.News == id && p.Status != (short)Commons.Status.Deleted).OrderByDescending(p => p.Id).ToList());
     }
 }
Exemplo n.º 10
0
        public ActionResult account()
        {
            int userID = int.Parse(Request.Cookies["uID"]);
            List <User_Table> userData = new List <User_Table>();

            using (var db = new ModelDbContext())
            {
                userData = db.Users
                           .Where(x => x.User_Id == userID)
                           .ToList();
            }

            var user = new UserModel()
            {
                firstName   = userData[0].First_Name,
                lastName    = userData[0].Last_Name,
                email       = userData[0].Email,
                password    = userData[0].Password,
                phone       = userData[0].phone,
                address     = userData[0].Address,
                address2    = userData[0].Adress2,
                city        = userData[0].City,
                state       = userData[0].State,
                zipCode     = userData[0].Zip,
                specialty   = userData[0].Specialty,
                designation = userData[0].Degree,
                UserId      = userID
            };

            return(View(user));
        }
Exemplo n.º 11
0
        public void GetByPersnrTest()
        {
            var options = CreateNewContextOptions();

            // Run the test against one instance of the context
            using (var context = new ModelDbContext(options))
            {
                List <Person> list = createData();

                foreach (var p in list)
                {
                    context.Person.Add(p);
                }

                context.SaveChanges();

                PersonCreateUpdateDeleteFake crudFake   = new PersonCreateUpdateDeleteFake();
                PersonController             controller = new PersonController(context, crudFake);

                var response = controller.GetByPersnr("min", "pse", 12345);

                Assert.True(response.success == "true");

                Assert.True(response.result.First().ForNamn == "Per");
            }
        }
Exemplo n.º 12
0
 public ICollection <tblGroup> GetAll()
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblGroups.Where(p => p.Status != (short)Commons.Status.Deleted).OrderByDescending(p => p.Id).ToList());
     }
 }
Exemplo n.º 13
0
 public ICollection <tblGroup> GetByParent(short parent)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblGroups.Where(p => p.Status != (short)Commons.Status.Deleted && p.ParentId == parent).OrderByDescending(p => p.Id).Include(p => p.Childrens).ToList());
     }
 }
Exemplo n.º 14
0
        private async Task SoftUpdateMpanFields(ModelDbContext dbContext, Site newSite, Mpan existing, MpanDto updatedDto)
        {
            SetPropertyIfNotNull(existing, e => e.IsEnergized, updatedDto.IsEnergized);
            SetPropertyIfNotNull(existing, e => e.IsNewConnection, updatedDto.IsNewConnection);
            SetPropertyIfNotNull(existing, e => e.EAC, updatedDto.EAC);
            SetPropertyIfNotNull(existing, e => e.REC, updatedDto.REC);
            SetPropertyIfNotNull(existing, e => e.Capacity, updatedDto.Capacity);
            SetPropertyIfNotNull(existing, e => e.CCLEligible, updatedDto.CCLEligible);
            SetPropertyIfNotNull(existing, e => e.VATPercentage, updatedDto.VATPercentage);
            SetPropertyIfNotNull(existing, e => e.IsAMR, updatedDto.IsAMR);

            SetStringPropertyIfNotNullOrEmpty(existing, e => e.MeterType, updatedDto.MeterType);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.MeterTimeSwitchCode, updatedDto.MeterTimeSwitchCode);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.LLF, updatedDto.LLF);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.ProfileClass, updatedDto.ProfileClass);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.RetrievalMethod, updatedDto.RetrievalMethod);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.GSPGroup, updatedDto.GSPGroup);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.MeasurementClass, updatedDto.MeasurementClass);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.MOAgent, updatedDto.MOAgent);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.DAAgent, updatedDto.DAAgent);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.DCAgent, updatedDto.DCAgent);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.SerialNumber, updatedDto.SerialNumber);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.Voltage, updatedDto.Voltage);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.Postcode, updatedDto.Postcode);
            SetStringPropertyIfNotNullOrEmpty(existing, e => e.Connection, updatedDto.Connection);

            existing.TariffId = updatedDto.TariffId;
            existing.Site     = newSite;

            await dbContext.Update(existing);
        }
        public ActionResult Update(string staffid, string percentage, string project, string memo)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(null);
            }
            if (staffid == null || staffid.IsEmpty() ||
                percentage == null || percentage.IsEmpty() ||
                project == null || project.IsEmpty() ||
                memo == null || memo.IsEmpty()
                )
            {
                return(null);
            }
            ModelDbContext      mdb            = new ModelDbContext();
            IQueryable <Domain> workPercetages = mdb.Domains;
            int    staff = int.Parse(staffid);
            Domain aim   = (from workPercetage in workPercetages
                            where workPercetage.StaffId == staff
                            select workPercetage).First();

            aim.Percentage = 100 > int.Parse(percentage) ? int.Parse(percentage) : 100;
            aim.Project    = project;
            aim.Memo       = memo;
            mdb.SaveChanges();
            return(null);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Get Product elements from Database
 /// </summary>
 /// <returns>List of Products</returns>
 private List <ProductModel> GetProductByDataBase()
 {
     using (ModelDbContext DbContext = new ModelDbContext())
     {
         return(DbContext.Product.ToList());
     }
 }
Exemplo n.º 17
0
 public tblUser GetById(int id)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblUsers.Find(id));
     }
 }
Exemplo n.º 18
0
        public ActionResult CEData(string id)
        {
            int myId = 422;

            if (id != null)
            {
                myId = int.Parse(id.ToString());
            }
            List <asimCEData> myCEData = new List <asimCEData>();

            using (var db = new ModelDbContext())
            {
                myCEData = db.Cases
                           .Where(x => x.Case_Id == myId)
                           .Select(x => new asimCEData {
                    case_id = x.Case_Id, ce_data = x.CE_Data
                })
                           .ToList();
            }
            asimViewModel objViewModel = new asimViewModel()
            {
                myCEData = myCEData
            };

            return(View(objViewModel));
        }
Exemplo n.º 19
0
 public ICollection <tblUser> GetByStatusPaging(short status, int pageNumber, int pageSize)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblUsers.Where(p => p.Status == status).OrderByDescending(p => p.Id).Skip(pageNumber * pageSize).Take(pageNumber).ToList());
     }
 }
 // GET: LibCards/Details/5
 public ActionResult Details(int id)
 {
     using (ModelDbContext db = new ModelDbContext())
     {
         return(View(db.THETHUVIENs.Where(x => x.MATHETV == id).FirstOrDefault()));
     }
 }
Exemplo n.º 21
0
 public IPagedList <tblUser> GetByStatusPageList(short status, int pageNumber, int pageSize)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblUsers.Where(p => p.Status == status).OrderByDescending(p => p.Id).ToPagedList(pageNumber, pageSize));
     }
 }
Exemplo n.º 22
0
 // GET: Muonsach
 public ActionResult Index()
 {
     using (ModelDbContext Dbmodel = new ModelDbContext())
     {
         return(View(Dbmodel.MUONSACKs.ToList()));
     }
 }
Exemplo n.º 23
0
 public tblUser GetByUserName(string userName)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblUsers.SingleOrDefault(p => p.UserName.ToLower().Equals(userName.ToLower().Trim())));
     }
 }
Exemplo n.º 24
0
 // GET: Muonsach/Delete/5
 public ActionResult Delete(int id)
 {
     using (ModelDbContext modelDbContext = new ModelDbContext())
     {
         return(View(modelDbContext.MUONSACKs.Where(x => x.MAMUONSACH == id).FirstOrDefault()));
     }
 }
Exemplo n.º 25
0
 public bool InsertAndUpdate(tblUser user)
 {
     using (var db = new ModelDbContext())
     {
         var item = new tblUser()
         {
             Id = user.Id
         };
         if (db.tblUsers.Any(p => p.Id == user.Id))
         {
             db.tblUsers.Attach(item);
             item.FullName   = user.FullName;
             item.ModifyDate = DateTime.Now;
             item.UserName   = user.UserName;
             item.Password   = Commons.Encode.MD5(user.Password);
             item.Img        = user.Img;
             item.ImgResizer = user.ImgResizer;
             item.Email      = user.Email;
         }
         else
         {
             db.tblUsers.Add(user);
         }
         return(db.SaveChanges() > 0);
     }
 }
Exemplo n.º 26
0
 public ICollection <tblSupport> GetAll()
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblSupports.OrderByDescending(p => p.CreateDate).ToList());
     }
 }
        public IActionResult Delete(int id)
        {
            try
            {
                using (ModelDbContext db = new ModelDbContext())
                {
                    var x = db.Employees.FirstOrDefault(x => x.ID == id);

                    if (x == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        db.Employees.Remove(x);
                        db.SaveChanges();

                        return(Ok());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 28
0
 public tblSupport GetById(int id)
 {
     using (var db = new ModelDbContext())
     {
         return(db.tblSupports.Find(id));
     }
 }
        public IActionResult Put(int id, [FromBody] Employee emp)
        {
            try
            {
                using (ModelDbContext db = new ModelDbContext())
                {
                    var x = db.Employees.FirstOrDefault(x => x.ID == id);

                    if (x == null)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        x.FirstName = emp.FirstName;
                        x.LastName  = emp.LastName;
                        x.Gender    = emp.Gender;
                        x.Salary    = emp.Salary;

                        db.SaveChanges();
                        return(Ok());
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 30
0
        public UnitOfWork(ModelDbContext context)
        {
            Context      = context;
            Repositories = new Dictionary <Type, object>();

            LoadRepos("GamesPardinho.Web.Models.Repository.Repositories");
        }