コード例 #1
0
        public static void MergeCompanies(DBPlatform context, string primaryMerge, IEnumerable <int> mergedIds)
        {
            if (String.IsNullOrEmpty(primaryMerge) || !mergedIds.Any())
            {
                return;
            }
            var primaryCompany = context.Companies.FirstOrDefault(comp => comp.name == primaryMerge);

            if (primaryCompany == null)
            {
                primaryCompany = new Company {
                    name = primaryMerge
                };
                context.Companies.Add(primaryCompany);
                context.Entry(primaryCompany).State = EntityState.Added;
            }
            var resCompanies = context.Companies.Include(co => co.Contacts)
                               .Where(comp => mergedIds.Contains(comp.Id)).ToList();

            foreach (var comp in resCompanies)
            {
                if (comp.Contacts.Count > 0)
                {
                    foreach (var cont in comp.Contacts.ToList())
                    {
                        cont.Company = primaryCompany;
                        context.Entry(cont).State = EntityState.Modified;
                    }

                    context.Companies.Remove(comp);
                }
            }

            context.SaveChanges();
        }
コード例 #2
0
        public ActionResult Edit(TitleEditView editView, string submitbutton)
        {
            //if (ModelState.IsValid)
            //{
            //    return ("Good");
            //}

            if (editView.Title.Name == null)
            {
                TempData["EmptyName"] = ViewData;
                return(RedirectToAction("Edit", editView.Title.Id));
            }
            Title title;

            if (submitbutton == "Save")
            {
                title = dbNew.Titles.Find(editView.Title.Id);
            }
            else
            {
                title = editView.Title;
            }
            if (title.Name != editView.Title.Name && dbNew.Titles.FirstOrDefault(co => co.Name == editView.Title.Name) != null)
            {
                TempData["NameExist"] = ViewData;
                return(RedirectToAction("Edit", title.Id));
                //return View("~/Views/Shared/Error.cshtml");
                //ModelState.AddModelError("", "Title Already Exist");
                //return View(editView);
            }

            else
            {
                title.JobAreas.Clear();
                title.Name       = editView.Title.Name;
                title.JobLevelId = editView.Title.JobLevelId;
                if (editView.selectedJobAreas != null)
                {
                    foreach (var c in dbNew.JobAreas.Where(area => editView.selectedJobAreas.Contains(area.Id)))
                    {
                        title.JobAreas.Add(c);
                    }
                }

                if (submitbutton == "Save")
                {
                    dbNew.Entry(title).State = EntityState.Modified;
                }
                else
                {
                    dbNew.Titles.Add(title);
                }
                dbNew.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
コード例 #3
0
        public ActionResult AddIndustryAlias(string aliasName, int?Id)
        {
            if (aliasName != null && Id != null)
            {
                var indExist = dbNew.Industries.FirstOrDefault(ind => ind.Name == aliasName);
                if (indExist == null)
                {
                    var indAliasExist = dbNew.IndustryAliases.FirstOrDefault(a => a.Name == aliasName);
                    var industry      = dbNew.Industries.Find(Id);
                    if (industry != null)
                    {
                        if (indAliasExist != null && indAliasExist.Industry == null)
                        {
                            industry.Aliases.Add(indAliasExist);
                        }
                        else if (indAliasExist == null)
                        {
                            industry.Aliases.Add(new IndustryAlias {
                                Name = aliasName
                            });
                        }
                        dbNew.Entry(industry).State = EntityState.Modified;
                        dbNew.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("Industries"));
        }
コード例 #4
0
        public ActionResult Edit(ContactEditView editView)
        {
            var cont = db.Contacts.Find(editView.Id);

            if (cont == null)
            {
                return(HttpNotFound());
            }
            if (cont.email != editView.email && db.Contacts.FirstOrDefault(con => con.email == editView.email) != null)
            {
                ModelState.AddModelError("", "Email already Exist");
                editView.updateInfo(db.Companies, db.Titles, db.Countries);
                return(View(editView));
            }
            else
            {
                cont.getNewInfo(editView);
                db.Entry(cont).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
コード例 #5
0
 public ActionResult DemodeUser(int?id)
 {
     using (DBPlatform db = new DBPlatform())
     {
         var user = db.Users.Find(id);
         if (user != null)
         {
             if (user.Role == "Moderator")
             {
                 user.Role            = "User";
                 db.Entry(user).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
     }
     return(RedirectToAction("Users"));
 }
コード例 #6
0
        public ActionResult Edit(CompanyEditView editView, int[] selectedIndustries, string submitbutton)
        {
            if (editView.company.name == null)
            {
                TempData["EmptyName"] = ViewData;
                return(RedirectToAction("Edit", editView.company.Id));
            }
            if (!editView.company.isMinMaxGood())
            {
                TempData["MinMax"] = ViewData;
                return(RedirectToAction("Edit", editView.company.Id));
            }
            Company comp = new Company();

            if (submitbutton == "Save")
            {
                comp = dbNew.Companies.Find(editView.company.Id);
                if (comp == null)
                {
                    return(HttpNotFound());
                }
            }

            if (comp.name != editView.company.name && dbNew.Companies.FirstOrDefault(co => co.name == editView.company.name) != null)
            {
                TempData["NameExist"] = ViewData;
                return(RedirectToAction("Edit", comp.Id));
            }
            else
            {
                comp.Industries.Clear();
                comp.getCompanyChanges(editView.company);

                if (editView.company.PrimaryIndustryId == null && selectedIndustries != null)
                {
                    comp.PrimaryIndustryId = selectedIndustries[new Random().Next(0, selectedIndustries.Count())];
                }
                else if (editView.company.PrimaryIndustryId != null && selectedIndustries == null)
                {
                    comp.Industries.Add(dbNew.Industries.Find(editView.company.PrimaryIndustryId));
                }


                // comp.Industries.Clear();
                if (selectedIndustries != null)
                {
                    //получаем выбранные курсы
                    foreach (var c in dbNew.Industries.Where(ind => selectedIndustries.Contains(ind.Id)))
                    {
                        comp.Industries.Add(c);
                    }
                }


                if (submitbutton == "Save")
                {
                    dbNew.Entry(comp).State = EntityState.Modified;
                }
                else
                {
                    dbNew.Companies.Add(comp);
                }
                dbNew.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }