Example #1
0
        public HttpResponseMessage Put([FromUri] int id, [FromBody] Models.Student sss)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Student s = Mapper.Map <Student>(sss);

                    if ((from ss in db.Students where ss.ID == id select ss.ID).Count() == 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }

                    db.Students.Attach(s);
                    db.Entry(s).State = EntityState.Modified;
                    db.SaveChanges();

                    s = db.Students.Find(id);

                    return(Request.CreateResponse <Models.Student>(HttpStatusCode.Created, Mapper.Map <Models.Student>(s)));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError));
                }
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
Example #2
0
    private void BtnSave_Click(object sender, EventArgs e)
    {
        long id = long.Parse((sender as Button).CommandArgument);

        using (StrPO_2018Entities db = new StrPO_2018Entities())
        {
            var dbObject = editor.Data;
            dbObject.ID = id;


            db.Students.Attach(dbObject);
            db.Entry(dbObject).State = System.Data.Entity.EntityState.Modified;

            /*(from s in db.Students where s.ID == id select s).FirstOrDefault();
             * if (dbObject == null)
             * {
             * ShowError(string.Format("Student with ID = {0} is not found", id));
             * return;
             * }
             * dbObject.Name = txtName.Text;
             * dbObject.Surname = txtSurname.Text;
             * dbObject.Group = int.Parse(txtGroup.Text);
             * dbObject.Course = int.Parse(txtCourse.Text);*/
            db.SaveChanges();
        }
        Response.Redirect("MainForm.aspx");
    }