Exemplo n.º 1
0
        private async Task<int> AddEdu()
        {
            try
            {
                int tmp = Convert.ToInt16(TxtbxYear.Text);

                using (var db = new CVDBContext())
                {
                    var query = from edu in db.Educations
                                where edu.EDU_ID == IDtoshow
                                select edu;

                    if (query.Count() < 1)
                    {
                        eduToAdd = new Educations
                        {
                            Course = TxtbxCourse.Text,
                            Degree = TxtbxDegree.Text,
                            Year = Convert.ToInt16(TxtbxYear.Text),
                            Notes = TxtbxNotes.Text,
                            School = TxtbxSchool.Text
                        };
                        db.Educations.Add(eduToAdd);
                        db.Entry(eduToAdd).State = EntityState.Added;
                        await db.SaveChangesAsync();
                        eduID = eduToAdd.GetEduID();
                    }
                    else
                    {
                        eduToAdd = query.FirstOrDefault();
                        eduToAdd.Course = TxtbxCourse.Text;
                        eduToAdd.Degree = TxtbxDegree.Text;
                        eduToAdd.Year = Convert.ToInt16(TxtbxYear.Text);
                        eduToAdd.Notes = TxtbxNotes.Text;
                        eduToAdd.School = TxtbxSchool.Text;
                        eduID = eduToAdd.EDU_ID;
                        db.Entry(eduToAdd).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                return eduID;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.InnerException, "add education error");
                return 0;
            }
        }
Exemplo n.º 2
0
        private async Task<int?> Save_Ref()
        {
            //return 1;
            //int tmp = 0;
            //if (TxtbxCompany.Text.Length > 0)
            //{
            //    tmp = await SaveCompany(TxtbxCompany.Text);
            //}
            try
            {
                using (var db = new CVDBContext())
                {
                    int? tmp = null;
                    Employment_Histories e = db.Employment_Histories.Find(emp_hisID);
                    if (e != null)
                    {
                        tmp = e.REF_ID;
                        refID = e.REF_ID;
                    }
                    if (tmp < 1 || tmp == null)
                    {
                        if (TxtbxCompanyRef.Text.Length > 0 &&
                            TxtbxEmailRef.Text.Length > 0 &&
                            TxtbxFirstNameRef.Text.Length > 0 &&
                            TxtbxLastNameRef.Text.Length > 0 &&
                            TxtbxMobileRef.Text.Length > 0 &&
                            TxtbxPhoneRef.Text.Length > 0 &&
                            TxtbxTitleRef.Text.Length > 0)
                        {
                            return null;
                        }
                        else
                        {
                            User_References ur = new User_References
                            {
                                Company_ID = coID, //await SaveCompany(TxtbxCompany.Text),
                                First_Name = TxtbxFirstNameRef.Text,
                                Last_Name = TxtbxLastNameRef.Text,
                                Title = TxtbxTitleRef.Text,
                                Phone = TxtbxPhoneRef.Text,
                                Mobile = TxtbxMobileRef.Text,
                                Email = TxtbxEmailRef.Text
                            };
                            db.User_References.Add(ur);
                            db.Entry(ur).State = EntityState.Added;
                            await db.SaveChangesAsync();
                            PopupAddRef.IsOpen = false;
                            return ur.REF_ID;
                        }
                    }
                    User_References u_r = db.User_References.Find(refID);
                    u_r.First_Name = TxtbxFirstNameRef.Text;
                    u_r.Last_Name = TxtbxLastNameRef.Text;
                    u_r.Title = TxtbxTitleRef.Text;
                    u_r.Phone = TxtbxPhoneRef.Text;
                    u_r.Mobile = TxtbxMobileRef.Text;
                    u_r.Email = TxtbxEmailRef.Text;
                    db.Entry(u_r).State = EntityState.Modified;
                    db.SaveChanges();

                    return u_r.REF_ID;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.InnerException, "Save Error");
                return null;
            }
        }
 public static async Task<int> Save(this Adresses a)
 {
     using (var db = new CVDBContext())
     {
         if (a.Adress_ID < 1)
         {
             db.Adresses.Add(a);
             db.Entry(a).State = EntityState.Added;
         }
         else
         {
             db.Entry(a).State = EntityState.Modified;
         }
         await db.SaveChangesAsync();
         return a.Adress_ID;
     }
 }
Exemplo n.º 4
0
        private async Task<int> SaveCompany(string str)
        {
            using (var db = new CVDBContext())
            {
                Companies co = db.Companies.Find(GetCompanyID(str));

                if (co == null)
                {
                    co = new Companies
                    {
                        Company_Name = str
                    };
                    db.Companies.Add(co);
                    db.Entry(co).State = EntityState.Added;
                    await db.SaveChangesAsync();
                    coID = GetCompanyID(co.Company_Name);
                    return coID;
                }
                else
                {
                    coID = co.Company_ID;
                    return coID;
                }
            }
        }