Exemple #1
0
        private static void RegionalUnity(object vPreviousColumn, object v1)
        {
            if (v1 != null && !string.IsNullOrWhiteSpace(v1.ToString()))
            {
                using (mydbContext context = new mydbContext())
                {
                    Region regType = new Region();
                    regType = context.Region.FirstOrDefault(x => x.RegionDescr.Equals(vPreviousColumn.ToString().Trim()));
                    if (regType == default(Region))
                    {
                        regType = new Region();
                        int?maxID = context.Region.Count().Equals(0) ? default(int?) : context.Region.Max(x => x.RegionId);
                        regType.RegionId    = maxID.HasValue ? maxID.Value + 1 : 1;
                        regType.RegionDescr = vPreviousColumn.ToString().Trim();
                        context.Region.Add(regType);
                        context.SaveChanges();
                    }


                    Regionalunity rType = new Regionalunity();
                    rType = context.Regionalunity.FirstOrDefault(x => x.RegionalUnityDescr.Equals(v1.ToString().Trim()));
                    if (rType == default(Regionalunity))
                    {
                        rType = new Regionalunity();
                        int?maxID = context.Regionalunity.Count().Equals(0) ? default(int?) : context.Regionalunity.Max(x => x.RegionalUnityId);
                        rType.RegionalUnityId    = maxID.HasValue ? maxID.Value + 1 : 1;
                        rType.RegionalUnityDescr = v1.ToString().Trim();
                        rType.RegionRegionId     = regType.RegionId;
                        context.Regionalunity.Add(rType);
                        context.SaveChanges();
                    }
                    selectedBusiness.RegionalUnityRegionalUnityId = rType.RegionalUnityId;
                }
            }
        }
Exemple #2
0
 public void Create(int userId, string triggerType, string triggerValue, byte trgActivity)
 {
     _context.AcTrigger.Add(new AcTrigger {
         TrgUsrId    = userId,
         TrgTrtId    = (from trgt in _context.AcTriggerType where trgt.TrtName == triggerType select trgt.TrtId).Single(),
         TrgValue    = triggerValue,
         TrgActivity = trgActivity
     });
     _context.SaveChanges();
 }
Exemple #3
0
        /* public static LoggerService Instance
         * {
         *   get
         *   {
         *       if (_logger == null)
         *       {
         *           _logger = new LoggerService();
         *
         *       }
         *
         *       return _logger;
         *   }
         * }*/

        public void InsertEventLog(string value, int trtId, int?objId, int evsId)
        {
            AcEventLog eventLog = new AcEventLog
            {
                EvlDate     = DateTime.Now,
                EvlTrgValue = value,
                EvlTrtId    = trtId,
                EvlObjId    = objId,
                EvlEvsId    = evsId
            };

            _context.AcEventLog.Add(eventLog);
            _context.SaveChanges();
        }
        public ActionResult UploadFile(IFormFile file, string id)
        {
            try
            {
                if (file == null || file.Length == 0)
                {
                    return(Content("file not selected"));
                }
                if (file.Length > 0)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images/" + file.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }
                    Items st = (from s in _context.Items where s.Itemcode == id select s).First();
                    st.Picture = file.FileName;
                    _context.SaveChanges();
                }
                ViewBag.Message = "File Uploaded Successfully!!" + ":" + id;
                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewBag.Message = "File upload failed!!";
                return(View());
            }
        }
        private void HandleReceivedMessage(string content)
        {
            Employee emp = System.Text.Json.JsonSerializer.Deserialize <Employee>(content);

            context.Employee.Add(emp);
            context.SaveChanges();

            Debug.WriteLine($"Received Messsage {content}");
        }
        public AcAccess Create(AccessDto acs)
        {
            AcAccess acsNew = new AcAccess
            {
                AcsValidFrom      = acs.ValidFrom,
                AcsValidTo        = acs.ValidTo,
                AcsOpeningCounter = acs.Counter != null ? acs.Counter : -1,
                AcsUsrId          = acs.UsrId,
                AcsProId          = acs.ProId != null ? acs.ProId : (from pro in _context.AcProfil where pro.ProName == "guest" select pro.ProId).SingleOrDefault(),
                AcsObjId          = acs.ObjId
            };

            _context.AcAccess.Add(acsNew);
            _context.SaveChanges();
            acsNew.AcsObj = (from obj in _context.AcObject where obj.ObjId == acsNew.AcsObjId select obj)
                            .SingleOrDefault();
            return(acsNew);
        }
Exemple #7
0
 private void AddSpoilers(mydbContext mydb, posts post)
 {
     foreach (SpoilersItem item in Spoilers)
     {
         spoilers spoiler = new spoilers
         {
             name    = item.name,
             content = item.content,
             posts   = post
         };
         mydb.spoilers.Add(spoiler);
     }
     mydb.SaveChanges();
 }
Exemple #8
0
        public AcUser Create(AcUser user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password) && string.IsNullOrWhiteSpace(user.UsrEmail))
            {
                throw new AppException("Password and Email are required");
            }

            Console.WriteLine(user.UsrEmail);

            var order = _context.AcUser.FirstOrDefault(x => x.UsrEmail == user.UsrEmail);

            if (order != null)
            {
                throw new AppException("Email already taken");
            }

            if (user.UsrRolId == 0)
            {
                user.UsrRolId = (from rol in _context.AcRole where rol.RolName == "Gost" select rol.RolId).SingleOrDefault();
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);


            user.UsrCryptedPassword = passwordHash;
            user.UsrPasswordSalt    = passwordSalt;

            user.UsrActivity = 1;

            _context.AcUser.Add(user);
            _context.SaveChanges();

            return(user);
        }
 private void AddUser()
 {
     try
     {
         using (mydbContext db = new mydbContext())
         {
             db.User.Add(ForAddUser);
             Users.Add(ForAddUser);
             db.SaveChanges();
             ForAddUser = new User();
         }
     }
     catch (Exception e)
     {
     }
 }
Exemple #10
0
        private static void Business(DataRow v)
        {
            selectedBusiness.BusinessesAgemko        = v[2].ToString();
            selectedBusiness.BusinessesAmke          = v[4].ToString();
            selectedBusiness.BusinessesVat           = v[5].ToString();
            selectedBusiness.BusinessesDescr         = v[6].ToString();
            selectedBusiness.BusinessesDistinctTitle = v[7].ToString();
            selectedBusiness.BusinessesNumMembers    = v.IsNull(8) ? default(int?) : Convert.ToInt32(v[8].ToString());
            selectedBusiness.BusinessesAddress       = v[10].ToString();
            selectedBusiness.BusinessesEmail         = v[14].ToString();
            selectedBusiness.BusinessesRegisterDate  = v.IsNull(16) ? default(DateTime?) : Convert.ToDateTime(v[16].ToString());
            selectedBusiness.BusinessesReviewDate    = v.IsNull(17) ? default(DateTime?) : Convert.ToDateTime(v[17].ToString());

            using (mydbContext context = new mydbContext())
            {
                Businesses rType = new Businesses();

                if (string.IsNullOrWhiteSpace(selectedBusiness.BusinessesVat))
                {
                    if (!string.IsNullOrWhiteSpace(selectedBusiness.BusinessesAgemko))
                    {
                        rType = context.Businesses.FirstOrDefault(x => x.BusinessesAgemko.Equals(selectedBusiness.BusinessesAgemko));
                        if (rType == default(Businesses))
                        {
                            int?maxID = context.Businesses.Count().Equals(0) ? default(int?) : context.Businesses.Max(x => x.BusinessesId);
                            selectedBusiness.BusinessesId = maxID.HasValue ? maxID.Value + 1 : 1;
                            context.Businesses.Add(selectedBusiness);
                        }
                    }
                }
                else
                {
                    rType = context.Businesses.FirstOrDefault(x => x.BusinessesVat.Equals(selectedBusiness.BusinessesVat));
                    if (rType == default(Businesses))
                    {
                        int?maxID = context.Businesses.Count().Equals(0) ? default(int?) : context.Businesses.Max(x => x.BusinessesId);
                        selectedBusiness.BusinessesId = maxID.HasValue ? maxID.Value + 1 : 1;
                        context.Businesses.Add(selectedBusiness);
                    }
                }

                rType.StatusStatusId = selectedBusiness.StatusStatusId;
                rType.RepresentativeRepresentativeId = selectedBusiness.RepresentativeRepresentativeId;

                context.SaveChanges();
            }
        }
Exemple #11
0
        private void AddPost(mydbContext mydb)
        {
            posts post = new posts
            {
                name        = Name,
                description = Description,
                date_public = DatePublic,
                file        = TorrentPath,
                pre_post    = PrepostID,
                program_id  = ProgramID,
                visible     = 1,
                count_view  = 0
            };

            mydb.posts.Add(post);
            mydb.SaveChanges();
        }
        public void Add()
        {
            if (Name == null || Site == null || PlatformsID <= 0)
            {
                return;
            }

            mydbContext mydb     = new mydbContext();
            platforms   platform = mydb.platforms.Single(el => el.id == PlatformsID);

            programs prog = new programs
            {
                name      = Name,
                off_site  = Site,
                platforms = platform
            };

            mydb.programs.Add(prog);
            mydb.SaveChanges();
        }
Exemple #13
0
 private static void MainActivity(object v)
 {
     if (v != null && !string.IsNullOrWhiteSpace(v.ToString()))
     {
         using (mydbContext context = new mydbContext())
         {
             Mainactivity rType = new Mainactivity();
             rType = context.Mainactivity.FirstOrDefault(x => x.MainActivityDescr.Equals(v.ToString().Trim()));
             if (rType == default(Mainactivity))
             {
                 rType = new Mainactivity();
                 int?maxID = context.Mainactivity.Count().Equals(0) ? default(int?) : context.Mainactivity.Max(x => x.MainActivityId);
                 rType.MainActivityId    = maxID.HasValue ? maxID.Value + 1 : 1;
                 rType.MainActivityDescr = v.ToString().Trim();
                 context.Mainactivity.Add(rType);
                 context.SaveChanges();
             }
             selectedBusiness.MainActivityMainActivityId = rType.MainActivityId;
         }
     }
 }
Exemple #14
0
 private static void Status(object v)
 {
     if (v != null && !string.IsNullOrWhiteSpace(v.ToString()))
     {
         using (mydbContext context = new mydbContext())
         {
             Status rType = new Status();
             rType = context.Status.FirstOrDefault(x => x.StatusDescr.Equals(v.ToString().Trim()));
             if (rType == default(Status))
             {
                 rType = new Status();
                 int?maxID = context.Status.Count().Equals(0) ? default(int?) : context.Status.Max(x => x.StatusId);
                 rType.StatusId    = maxID.HasValue ? maxID.Value + 1 : 1;
                 rType.StatusDescr = v.ToString().Trim();
                 context.Status.Add(rType);
                 context.SaveChanges();
             }
             selectedBusiness.StatusStatusId = rType.StatusId;
         }
     }
 }
Exemple #15
0
        public void Add()
        {
            mydbContext mydb = new mydbContext();

            AddPost(mydb);

            posts post = mydb.posts
                         .OrderByDescending(el => el.id)
                         .First();

            AddScreen(mydb, post);
            AddSpoilers(mydb, post);

            preposts prPost = mydb.preposts.Single(el => el.id == PrepostID);

            prPost.itpublic = 1;
            mydb.SaveChanges();

            Program.statusBarGlobal.Message     = "Добавление поста";
            Program.statusBarGlobal.Description = "Пост успешно добавлен.";
        }
Exemple #16
0
 private static void IndividualCategory(object v)
 {
     if (v != null && !string.IsNullOrWhiteSpace(v.ToString()))
     {
         using (mydbContext context = new mydbContext())
         {
             Individualcategory rType = new Individualcategory();
             rType = context.Individualcategory.FirstOrDefault(x => x.IndividualCategoryDescr.Equals(v.ToString().Trim()));
             if (rType == default(Individualcategory))
             {
                 rType = new Individualcategory();
                 int?maxID = context.Individualcategory.Count().Equals(0) ? default(int?) : context.Individualcategory.Max(x => x.IndividualCategoryId);
                 rType.IndividualCategoryId    = maxID.HasValue ? maxID.Value + 1 : 1;
                 rType.IndividualCategoryDescr = v.ToString().Trim();
                 context.Individualcategory.Add(rType);
                 context.SaveChanges();
             }
             selectedBusiness.IndividualCategoryIndividualCategoryId = rType.IndividualCategoryId;
         }
     }
 }
Exemple #17
0
 private static void RegistryType(object v)
 {
     if (v != null && !string.IsNullOrWhiteSpace(v.ToString()))
     {
         using (mydbContext context = new mydbContext())
         {
             Registrytype rType = new Registrytype();
             rType = context.Registrytype.FirstOrDefault(x => x.RegistryTypeDescr.Equals(v.ToString().Trim()));
             if (rType == default(Registrytype))
             {
                 rType = new Registrytype();
                 int?maxID = context.Registrytype.Count().Equals(0) ? default(int?) : context.Registrytype.Max(x => x.RegistryTypeId);
                 rType.RegistryTypeId    = maxID.HasValue ? maxID.Value + 1 : 1;
                 rType.RegistryTypeDescr = v.ToString().Trim();
                 context.Registrytype.Add(rType);
                 context.SaveChanges();
             }
             selectedBusiness.RegistryTypeRegistryTypeId = rType.RegistryTypeId;
         }
     }
 }
        public void Add(DataGridViewSelectedRowCollection CategorsSelected)
        {
            mydbContext mydb = new mydbContext();
            programs    prog = mydb.programs
                               .OrderByDescending(el => el.id)
                               .First();

            foreach (DataGridViewRow item in CategorsSelected)
            {
                int        idCategory = int.Parse(item.Cells[0].Value.ToString());
                categories category   = mydb.categories.Single(el => el.id == idCategory);

                program_categories program_Categories = new program_categories
                {
                    programs   = prog,
                    categories = category
                };
                mydb.program_categories.Add(program_Categories);
            }
            mydb.SaveChanges();
        }
Exemple #19
0
        private void AddPostInDB(List <TrackersListItem> lst, Func <tracker, bool> tExpression)
        {
            tracker t = context.tracker.Single(tExpression);

            foreach (var item in lst)
            {
                preposts prepost = new preposts
                {
                    name     = item.Name,
                    href     = item.Href,
                    date     = DateTime.Today,
                    itpublic = 0,
                    tracker1 = t,
                    magnet   = item.Magnet,
                };
                context.preposts.Add(prepost);
            }
            context.SaveChanges();
            //dw вызываем событие после добавления в бд
            OnAfterAdd?.Invoke(this, EventArgs.Empty);
        }
Exemple #20
0
        private void AddScreen(mydbContext mydb, posts post)
        {
            images img = new images
            {
                href  = Imgs.Poster,
                type  = "post",
                posts = post
            };

            mydb.images.Add(img);

            if (Imgs.Screens != null)
            {
                foreach (string item in Imgs.Screens)
                {
                    img = new images
                    {
                        href  = item,
                        type  = "screen",
                        posts = post
                    };
                    mydb.images.Add(img);
                }
            }

            if (Imgs.Views != null)
            {
                foreach (string item in Imgs.Views)
                {
                    img = new images
                    {
                        href  = item,
                        type  = "view",
                        posts = post
                    };
                    mydb.images.Add(img);
                }
            }
            mydb.SaveChanges();
        }
 public void SaveNotAsync()
 {
     _mydb.SaveChanges();
 }
 public void Save2()
 {
     _mydb.SaveChanges();
 }