Ejemplo n.º 1
0
        public void Delete(long personId)
        {
            try
            {
                using (var db = new DatabaseContainer())
                {
                    Person p = db.Persons
                               .Include("User")
                               .Include("Candidate")
                               .Include("Candidate.Evaluation")
                               .Include("Candidate.Decision")
                               .Where(x => x.Id == personId).First();

                    db.Entry(p.Candidate.Evaluation).State = System.Data.Entity.EntityState.Deleted;
                    db.Entry(p.Candidate.Decision).State   = System.Data.Entity.EntityState.Deleted;
                    db.Entry(p.Candidate).State            = System.Data.Entity.EntityState.Deleted;
                    db.Entry(p.User).State = System.Data.Entity.EntityState.Deleted;
                    db.Entry(p).State      = System.Data.Entity.EntityState.Deleted;

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }
        }
        public void Editar(Categoria categoria)
        {
            //state estado do registro
            //entry entrada
            contexto.Entry(categoria).State = System.Data.Entity.EntityState.Modified;

            contexto.SaveChanges();
        }
Ejemplo n.º 3
0
        // PUT api/Item/5
        public HttpResponseMessage PutItem(int id, Item item)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != item.ID)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            db.Entry(item).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 4
0
        public bool Authenticate(string email, byte[] token, out byte attemptsLeft)
        {
            if (_salt == null || _authenticated)
            {
                attemptsLeft = 255;
                return(false);
            }

            using (var db = new DatabaseContainer())
            {
                var query = from u in db.UsersSet
                            where u.Email == email
                            select u;

                if (query.Count() == 0)
                {
                    attemptsLeft = 255;
                    return(false);
                }

                var user = query.First();

                attemptsLeft = user.AttemptsLeft;

                if (attemptsLeft == 0)
                {
                    return(false);
                }

                if (user.Online)
                {
                    attemptsLeft = 255;
                    return(false);
                }

                _authenticated = AuthChecker.CheckToken(token, _salt, user.Password);

                if (!_authenticated)
                {
                    attemptsLeft--;
                    user.AttemptsLeft--;
                }
                else
                {
                    user.AttemptsLeft = Config.MaxAuthAttempts;
                    user.Online       = true;
                    _email            = user.Email;
                    _id = user.Id;
                }

                var entry = db.Entry(user);
                entry.Property(e => e.AttemptsLeft).IsModified = true;
                entry.Property(e => e.Online).IsModified       = true;
                db.SaveChanges();
                _salt = null;
                return(_authenticated);
            }
        }
Ejemplo n.º 5
0
 public ActionResult Edit(Ad ad)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ad).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ad));
 }
Ejemplo n.º 6
0
 public ActionResult Edit(SubCategory subcategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(subcategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryID = new SelectList(db.Categories, "ID", "NameEN", subcategory.CategoryID);
     return(View(subcategory));
 }
Ejemplo n.º 7
0
 public ActionResult Edit(AdsResource adsresource)
 {
     if (ModelState.IsValid)
     {
         db.Entry(adsresource).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AdID = new SelectList(db.Ads, "ID", "TitleEN", adsresource.AdID);
     return(View(adsresource));
 }
Ejemplo n.º 8
0
        public long AddSoftSkill(Candidate candidate, SoftSkillsEvaluation skillEvaluation, string skillName)
        {
            try
            {
                using (var db = new DatabaseContainer())
                {
                    skillEvaluation.SoftSkill    = db.SoftSkills.Where(x => x.Name == skillName).First();
                    skillEvaluation.Mark         = skillEvaluation.Mark;
                    skillEvaluation.EvaluationId = candidate.Evaluation.Id;

                    db.Entry(skillEvaluation).State           = System.Data.Entity.EntityState.Added;
                    db.Entry(skillEvaluation.SoftSkill).State = System.Data.Entity.EntityState.Unchanged;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }

            return(skillEvaluation.Id);
        }
Ejemplo n.º 9
0
 public void DeleteDocumenyById(long id)
 {
     try
     {
         using (var db = new DatabaseContainer())
         {
             db.Entry(db.Documents.Where(x => x.Id == id).First()).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }
Ejemplo n.º 10
0
 public void DeleteStage(Stage stage)
 {
     try
     {
         using (var db = new DatabaseContainer())
         {
             db.Entry(db.Stage.Where(x => x.Id == stage.Id).First()).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }
Ejemplo n.º 11
0
 public void DeleteRecriutmentStage(RecruitmentStage rs)
 {
     try
     {
         using (var db = new DatabaseContainer())
         {
             db.Entry(db.RecruitmentStages.Where(x => x.Id == rs.Id).First()).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
Ejemplo n.º 12
0
 public void Delete(long candidateId)
 {
     try
     {
         using (var db = new DatabaseContainer())
         {
             db.Entry(db.Candidates.Where(x => x.Id == candidateId).First()).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw;
     }
 }
Ejemplo n.º 13
0
        public int SaveSoftSkill(Database.SoftSkill softSkill)
        {
            try
            {
                using (var db = new DatabaseContainer())
                {
                    db.Entry(softSkill).State = softSkill.Id == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }

            return(softSkill.Id);
        }
Ejemplo n.º 14
0
        public long SaveRecriutmentStage(RecruitmentStage rs)
        {
            try
            {
                using (var db = new DatabaseContainer())
                {
                    rs.Stage           = db.Stage.Where(x => x.Name == rs.Stage.Name).First();
                    db.Entry(rs).State = rs.Id == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }

            return(rs.Id);
        }
Ejemplo n.º 15
0
 public int SaveDocument(Document document, int candidateId, byte type)
 {
     try
     {
         using (var db = new DatabaseContainer())
         {
             document.CandidateId     = candidateId;
             document.Type            = type;
             db.Entry(document).State = document.Id == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
     return(document.Id);
 }
Ejemplo n.º 16
0
 public void DeleteSkill(Database.Skill skill)
 {
     try
     {
         using (var db = new DatabaseContainer())
         {
             if (db.SkillsEvaluations.Where(x => x.SkillId == skill.Id).Count() == 0)
             {
                 db.Entry(skill).State = System.Data.Entity.EntityState.Deleted;
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
     }
 }
Ejemplo n.º 17
0
        public int SaveStage(Stage stage)
        {
            try
            {
                using (var db = new DatabaseContainer())
                {
                    if (stage.Id == 0)
                    {
                        stage.Priority = db.Stage.Count() == 0 ? 1 : db.Stage.Max(x => x.Priority) + 1;
                    }

                    db.Entry(stage).State = stage.Id == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }

            return(stage.Id);
        }
Ejemplo n.º 18
0
        public int Save(Candidate candidate)
        {
            try
            {
                using (var db = new DatabaseContainer())
                {
                    db.Candidates.Attach(candidate);
                    db.Entry(candidate).State          = System.Data.Entity.EntityState.Modified;
                    db.Entry(candidate.Decision).State = System.Data.Entity.EntityState.Modified;

                    foreach (var rs in candidate.RecruitmentStage)
                    {
                        db.Entry(rs).State = System.Data.Entity.EntityState.Modified;
                    }

                    db.Entry(candidate.Evaluation).State = System.Data.Entity.EntityState.Modified;

                    foreach (var se in candidate.Evaluation.SkillsEvaluation)
                    {
                        db.Entry(se).State = System.Data.Entity.EntityState.Modified;
                    }

                    foreach (var sse in candidate.Evaluation.SoftSkillsEvaluation)
                    {
                        db.Entry(sse).State = System.Data.Entity.EntityState.Modified;
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }

            return(candidate.Id);
        }
Ejemplo n.º 19
0
        public int SaveC(Person person)
        {
            try
            {
                person.User.Role = (byte)UserRolesEnum.Candidate;
                using (var db = new DatabaseContainer())
                {
                    System.Data.Entity.EntityState state = person.Id == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
                    Person p = null;
                    if (state == System.Data.Entity.EntityState.Modified)
                    {
                        if (this.GetPersonById(person.Id).User.Login != person.User.Login)
                        {
                            if (db.Users.Where(x => x.Login == person.User.Login).Count() != 0)
                            {
                                throw new Exception();
                            }
                        }

                        p            = db.Persons.Include("User").Where(x => x.Id == person.Id).Single();
                        p.Mail       = person.Mail;
                        p.Name       = person.Name;
                        p.Pesel      = person.Pesel;
                        p.Phone      = person.Phone;
                        p.SurName    = person.SurName;
                        p.User.Login = person.Pesel;
                    }

                    if (person.Candidate == null)
                    {
                        db.Entry(new Candidate()
                        {
                            Person     = person,
                            Evaluation = new Evaluation(),
                            Decision   = new Decision()
                            {
                                Type = (byte)DecisionTypesEnum.DuringEvaluation
                            }
                        }).State = System.Data.Entity.EntityState.Added;
                    }

                    if (person.User.Password == string.Empty || person.User.Password == null)
                    {
                        if (state == System.Data.Entity.EntityState.Modified)
                        {
                            p.User.Password = db.Users.Where(x => x.Id == person.User.Id).First().Password;
                        }

                        person.User.Password = db.Users.Where(x => x.Id == person.User.Id).First().Password;
                    }
                    else
                    {
                        if (state == System.Data.Entity.EntityState.Modified)
                        {
                            p.User.Password = Common.Encryption.Encrypt(person.User.Password);
                        }
                        person.User.Password = Common.Encryption.Encrypt(person.User.Password);
                    }

                    if (state == System.Data.Entity.EntityState.Added)
                    {
                        db.Entry(person).State      = System.Data.Entity.EntityState.Added;
                        db.Entry(person.User).State = System.Data.Entity.EntityState.Added;
                    }
                    else
                    {
                        db.Entry(p).State = System.Data.Entity.EntityState.Modified;
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                return(0);
            }

            return(person.Id);
        }
Ejemplo n.º 20
0
        public int Save(Person person)
        {
            try
            {
                using (var db = new DatabaseContainer())
                {
                    System.Data.Entity.EntityState state = person.Id == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;

                    if (state == System.Data.Entity.EntityState.Modified)
                    {
                        if (this.GetPersonById(person.Id).User.Login != person.User.Login)
                        {
                            if (db.Users.Where(x => x.Login == person.User.Login).Count() != 0)
                            {
                                throw new Exception();
                            }
                        }
                    }
                    else
                    {
                        if (db.Users.Where(x => x.Login == person.User.Login).Count() != 0)
                        {
                            throw new Exception();
                        }
                    }

                    db.Entry(person).State      = state;
                    db.Entry(person.User).State = state;

                    if (state == System.Data.Entity.EntityState.Added)
                    {
                        person.User.Password = Common.Encryption.Encrypt(person.User.Password);
                    }
                    else
                    {
                        if (person.User.Password == string.Empty)
                        {
                            person.User.Password = db.Users.Where(x => x.Id == person.User.Id).First().Password;
                        }
                        else
                        {
                            person.User.Password = Common.Encryption.Encrypt(person.User.Password);
                        }
                    }

                    if ((UserRolesEnum)person.User.Role == UserRolesEnum.Candidate)
                    {
                        if (person.Candidate == null)
                        {
                            db.Entry(new Candidate()
                            {
                                Person     = person,
                                Evaluation = new Evaluation(),
                                Decision   = new Decision()
                                {
                                    Type = (byte)DecisionTypesEnum.DuringEvaluation
                                }
                            }).State = System.Data.Entity.EntityState.Added;
                        }
                        else
                        {
                            db.Entry(person.Candidate).State = state;
                        }
                    }
                    else
                    {
                        if (person.Candidate != null)
                        {
                            Candidate c = db.Candidates
                                          .Include("Evaluation")
                                          .Include("Decision").Where(x => x.Id == person.Candidate.Id).First();

                            db.Entry(c.Evaluation).State = System.Data.Entity.EntityState.Deleted;

                            db.Entry(c.Decision).State = System.Data.Entity.EntityState.Deleted;

                            db.Entry(c).State = System.Data.Entity.EntityState.Deleted;
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
            }

            return(person.Id);
        }