private void buttonSelectContact_Click(object sender, EventArgs e)
        {
            Select_Contact_Form SelectContactF = new Select_Contact_Form();

            SelectContactF.ShowDialog();

            try
            {
                int contactId = Convert.ToInt32(SelectContactF.dataGridView1.CurrentRow.Cells[0].Value.ToString());

                CONTACT   contact = new CONTACT();
                DataTable table   = contact.GetContactById(contactId);

                textBoxContactId.Text       = table.Rows[0]["id"].ToString();
                textBoxFName.Text           = table.Rows[0]["fname"].ToString();
                textBoxLName.Text           = table.Rows[0]["lname"].ToString();
                comboBoxGroup.SelectedValue = table.Rows[0]["group_id"];
                textBoxPhone.Text           = table.Rows[0]["phone"].ToString();
                textBoxEmail.Text           = table.Rows[0]["email"].ToString();
                textBoxAddress.Text         = table.Rows[0]["address"].ToString();

                byte[]       pic     = (byte[])table.Rows[0]["pic"];
                MemoryStream picture = new MemoryStream(pic);
                pictureBoxContactImage.Image = Image.FromStream(picture);
            }
            catch (Exception)
            {
            }
        }
예제 #2
0
        public JsonResult Send(string name, string email, string title, string detail)
        {
            var contact = new CONTACT
            {
                datebegin = DateTime.Now,
                username  = name,
                email     = email,
                title     = title,
                detail    = detail
            };

            var id = new ContactDAO().InsertContact(contact);

            if (id > 0)
            {
                return(Json(new
                {
                    status = true
                }));
            }
            else
            {
                return(Json(new
                {
                    status = false
                }));
            }
        }
        private void buttonEditContact_Click(object sender, EventArgs e)
        {
            CONTACT contact = new CONTACT();

            string fname   = textBoxFName.Text;
            string lname   = textBoxLName.Text;
            string phone   = textBoxPhone.Text;
            string address = textBoxAddress.Text;
            string email   = textBoxEmail.Text;

            try
            {
                int id = Convert.ToInt32(textBoxContactId.Text);

                int groupid = (int)comboBoxGroup.SelectedValue;

                MemoryStream pic = new MemoryStream();
                pictureBoxContactImage.Image.Save(pic, pictureBoxContactImage.Image.RawFormat);

                if (contact.updateContact(id, fname, lname, phone, address, email, groupid, pic))
                {
                    MessageBox.Show("Contact Information UpDated", "Edit Contact", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Error", "Edit Contact", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Edit Contact", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public bool Add(ContactModel contactModel)
        {
            bool addflag = false;

            try
            {
                CONTACT objContact = new CONTACT();
                objContact.FirstName = contactModel.FirstName;
                objContact.LastName  = contactModel.LastName;

                objContact.DateofBirth = contactModel.DateofBirth;
                objContact.EmailIds    = contactModel.Emails != null?string.Join(",", contactModel.Emails.Select(x => x.Email).ToArray()) : string.Empty;

                objContact.PhoneNumbers = contactModel.PhoneNumbers != null?string.Join(",", contactModel.PhoneNumbers.Select(x => x.PhoneNumber).ToArray()) : string.Empty;

                db.CONTACTS.Add(objContact);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                addflag = false;
                throw ex;
            }
            return(addflag = true);
        }
예제 #5
0
        public JsonResult GetContactByCusId(string ID)
        {
            CONTACT        con = new CONTACT();
            List <CONTACT> lst = con.SelectCusContact(ID);

            return(Json(lst));
        }
예제 #6
0
        public IHttpActionResult PostCONTACT(CONTACT cONTACT)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CONTACTs.Add(cONTACT);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CONTACTExists(cONTACT.CONTACT_ID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = cONTACT.CONTACT_ID }, cONTACT));
        }
예제 #7
0
        public void TestEditPost()
        {
            var db    = new CsK23T2bEntities();
            var model = new CONTACT
            {
                idContact  = db.CONTACTs.AsNoTracking().First().idContact,
                tenContact = "789"
            };
            var controller = new ContactController();

            using (var scope = new TransactionScope())
            {
                var result = controller.Create(model);
                var view   = result as ViewResult;


                controller = new ContactController();
                result     = controller.Edit(model);

                var redirect = result as RedirectToRouteResult;

                Assert.IsNotNull(redirect);
                Assert.AreEqual("Index", redirect.RouteValues["action"]);

                var item = db.CONTACTs.Find(model.idContact);

                Assert.IsNotNull(item);
                Assert.AreEqual(model.tenContact, item.tenContact);
            }
        }
예제 #8
0
        public IHttpActionResult PutCONTACT(int id, CONTACT cONTACT)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cONTACT.CONTACT_ID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CONTACTExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #9
0
        public ActionResult contact(CONTACT data)
        {
            if (data.ID > 0)
            {
                var conf = db.CONTACTs.Where(i => i.ID == data.ID).SingleOrDefault();
                if (conf != null)
                {
                    conf.UPDATED_DATE = DateTime.Now;
                    if (data.NAME != null)
                    {
                        conf.NAME = data.NAME;
                    }
                    conf.PHONE   = data.PHONE;
                    conf.EMAIL   = data.EMAIL;
                    conf.SUBJECT = data.SUBJECT;
                    conf.MESSAGE = data.MESSAGE;

                    db.SaveChanges();
                }
            }
            else
            {
                data.CREATED_DATE = DateTime.Now;

                var time = db.CONTACTs.Add(data);
                db.SaveChanges();
            }
            return(RedirectToAction("contact"));
        }
예제 #10
0
        public void TestCreatePost()
        {
            var db    = new CsK23T2bEntities();
            var model = new CONTACT
            {
                tenNguoidung   = "Nguyen",
                tenContact     = "123",
                sdt            = 123456,
                noidungContact = "khong co"
            };
            var controller = new ContactController();

            using (var scope = new TransactionScope()){
                var result = controller.Create(model);


                var redirect = result as RedirectToRouteResult;

                Assert.IsNotNull(redirect);
                Assert.AreEqual("Index", redirect.RouteValues["action"]);

                var item = db.CONTACTs.Find(model.idContact);

                Assert.IsNotNull(item);
                Assert.AreEqual(model.tenNguoidung, item.tenNguoidung);
                Assert.AreEqual(model.tenContact, item.tenContact);
                Assert.AreEqual(model.sdt, item.sdt);
                Assert.AreEqual(model.noidungContact, item.noidungContact);
            }
        }
        private void Select_Contact_Form_Load(object sender, EventArgs e)
        {
            CONTACT    contact = new CONTACT();
            SqlCommand command = new SqlCommand("SELECT ID ,  FirstName  as 'first name',  LastName  as 'last name',  GroupID  as'group id' FROM  Contact  WHERE  UserID  = @uid");

            command.Parameters.Add("@uid", SqlDbType.Int).Value = Globals.GlobalUserId;
            dataGridView1.DataSource = contact.SelectContactList(command);
        }
예제 #12
0
        public JsonResult DeleteContact(string ID)
        {
            CONTACT con = new CONTACT();

            var result = con.Delete(ID);

            return(Json(result));
        }
예제 #13
0
        public ActionResult DeleteConfirmed(int id)
        {
            CONTACT cONTACT = db.CONTACTs.Find(id);

            db.CONTACTs.Remove(cONTACT);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #14
0
 /// <summary>
 /// This is a method purly becuase the view should not be aware of the models.
 /// </summary>
 /// <param name="contact"></param>
 public void SetCurrentContact(object contact)
 {
     //Check if selection is valid.
     if (contact == null || contact.ToString().Contains("NewItemPlaceholder"))
     {
         return;
     }
     CurrentContact = (CONTACT)contact;
 }
예제 #15
0
 internal void Update(CONTACT CONTACT)
 {
     using (entity = new klassycafeEntities())
     {
         ContactRepo = new GenericRepo <CONTACT>(entity);
         ContactRepo.Update(CONTACT);
         ContactRepo.Save();
     }
 }
예제 #16
0
        public ActionResult contact(CONTACT data)
        {
            information();
            data.CREATED_DATE = DateTime.Now;
            var cont = db.CONTACTs.Add(data);

            db.SaveChanges();
            return(View());
        }
예제 #17
0
 public ActionResult Edit([Bind(Include = "id,datebegin,username,email,title,detail")] CONTACT cONTACT)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cONTACT).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cONTACT));
 }
예제 #18
0
        /// <summary>
        /// DELET: from api
        /// </summary>
        /// <param name="id"></param>
        /// <param name="contact"></param>
        async private void DeleteContact(long id, CONTACT contact)
        {
            HttpResponseMessage responseMessage = await client.DeleteAsync(url + "/" + id);

            if (!responseMessage.IsSuccessStatusCode)
            {
                //Do not leave the app in an incorrect state, that can not be recovered from.
                throw new DataException("Could not DELETE from web api");
            }
        }
예제 #19
0
 public ActionResult Edit([Bind(Include = "ID,NAME,TELEPHONE,EMAIL,SUBJECTS,MESSAAGE,CURRENTTIME")] CONTACT cONTACT)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cONTACT).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cONTACT));
 }
예제 #20
0
 public ActionResult Edit(CONTACT model)
 {
     if (ModelState.IsValid)
     {
         db.Entry(model).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
예제 #21
0
        /// <summary>
        /// POST: to api
        /// </summary>
        /// <param name="contact"></param>
        async private void CreateContact(CONTACT contact)
        {
            HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, contact);

            if (!responseMessage.IsSuccessStatusCode)
            {
                //Do not leave the app in an incorrect state, that can not be recovered from.
                throw new DataException("Could not POST to web api");
            }
        }
예제 #22
0
        public JsonResult Delete(string ID)
        {
            CONTACT  con = new CONTACT();
            CUSTOMER cus = new CUSTOMER();

            con.DeleteContactByCusId(ID);
            var result = cus.Delete(ID);

            return(Json(result));
        }
예제 #23
0
        public ActionResult Create(CONTACT model)
        {
            if (ModelState.IsValid)
            {
                db.CONTACTs.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
예제 #24
0
        public JsonResult GetContact(string CUS_ID)
        {
            CUSTOMER cus = new CUSTOMER();
            CONTACT  vc  = new CONTACT();
            var      lst = vc.SelectCusContact(CUS_ID);

            cus = cus.Select(CUS_ID).FirstOrDefault();
            var result = new { CONTACTS = lst, CUSTOMER = cus };

            return(Json(result));
        }
예제 #25
0
        public IHttpActionResult GetCONTACT(int id)
        {
            CONTACT cONTACT = db.CONTACTs.Find(id);

            if (cONTACT == null)
            {
                return(NotFound());
            }

            return(Ok(cONTACT));
        }
예제 #26
0
        public ActionResult Contact()
        {
            if (Session["UserId"] == null)
            {
                return(RedirectToAction("Login"));
            }

            CONTACT settings = contactDA.Get();

            return(View(settings));
        }
예제 #27
0
        public ActionResult Create([Bind(Include = "ID,NAME,TELEPHONE,EMAIL,SUBJECTS,MESSAAGE,CURRENTTIME")] CONTACT cONTACT)
        {
            if (ModelState.IsValid)
            {
                db.CONTACTs.Add(cONTACT);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cONTACT));
        }
예제 #28
0
        public ActionResult Create([Bind(Include = "id,datebegin,username,email,title,detail")] CONTACT cONTACT)
        {
            if (ModelState.IsValid)
            {
                db.CONTACTs.Add(cONTACT);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cONTACT));
        }
        public ActionResult Create(string email, string title, string content)
        {
            var contact = new CONTACT();

            contact.EMAIL   = email;
            contact.TITLE   = title;
            contact.DATE    = DateTime.Now;
            contact.CONTENT = content;
            model.CONTACTs.Add(contact);
            model.SaveChanges();
            return(RedirectToAction("Index", "FOODs"));
        }
예제 #30
0
        public IHttpActionResult DeleteCONTACT(int id)
        {
            CONTACT cONTACT = db.CONTACTs.Find(id);

            if (cONTACT == null)
            {
                return(NotFound());
            }

            db.CONTACTs.Remove(cONTACT);
            db.SaveChanges();

            return(Ok(cONTACT));
        }