public APIResult AddListGioiTinh(List <GioiTinh> listGioiTinh)
        {
            var db     = new BCDHContext();
            var result = new APIResult();

            try
            {
                db.GioiTinh.AddRange(listGioiTinh);
                db.SaveChanges();
                result.error = new Error
                {
                    code            = "201",
                    internalMessage = "Success",
                    userMessage     = "Thêm thành công"
                };
            }
            catch (Exception ex)
            {
                result.error = new Error
                {
                    code            = "500",
                    internalMessage = ex.ToString(),
                    userMessage     = "Lỗi khi thêm"
                };
            }

            return(result);
        }
Ejemplo n.º 2
0
 public bool TruncateVanBan()
 {
     using (var db = new BCDHContext())
     {
         try
         {
             db.Database.ExecuteSqlCommand("truncate table [BCDH].[dbo].[VanBan]");
             db.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Ejemplo n.º 3
0
        public bool RandomOffice(int skip, int take)
        {
            Random rnd = new Random();
            int    officeRandom;

            using (var db = new BCDHContext())
            {
                var vanBans = db.VanBan
                              .OrderBy(x => x.ID)
                              .Skip(skip)
                              .Take(take)
                              .ToList();

                foreach (var item in vanBans)
                {
                    officeRandom = rnd.Next(1, 4); // Random 1- 3

                    switch (officeRandom)
                    {
                    case 1:
                        item.DonViXuLyChinh = "000-00-12-H40";
                        break;

                    case 2:
                        item.DonViXuLyChinh = "000-00-19-H40";
                        break;

                    case 3:
                        item.DonViXuLyChinh = "000-00-20-H40";
                        break;

                    default:
                        break;
                    }
                }

                db.SaveChanges();
            }

            return(true);
        }