コード例 #1
0
        public void saveChanges()
        {
            using (var db = new PlanningContext())
            {
                contact_type data = null;

                if (!this._isCreateMode)
                {
                    var id = Convert.ToInt32(this.contact_type_id.Text);
                    data = db.contact_type.Where(d => d.contact_type_id == id).FirstOrDefault();
                    if (data == null)
                    {
                        this._mainInterface.statusText = $"ERROR: ID '{this.contact_type_id.Text}' does not exist.";
                        return;
                    }
                }
                else
                {
                    data = new contact_type();
                }

                data.contact_type_id = Convert.ToInt32(this.contact_type_id.Text);
                data.description     = /**/ (this.description.Text);
                data.is_active       = (bool)this.is_active.IsChecked;
                data.comment         = /**/ (this.comment.Text);


                if (this._isCreateMode)
                {
                    db.contact_type.Add(data);
                }
                db.SaveChanges();
            }
        }
コード例 #2
0
 public async Task <IActionResult> Put(int id, [FromBody] contact_type entity)
 {
     try
     {
         if (id < 0 || !isValid(entity))
         {
             return(new BadRequestResult());
         }
         //sm(agent.Messages);
         return(Ok(await agent.Update <contact_type>(id, entity)));
     }
     catch (Exception ex)
     {
         //sm(agent.Messages);
         return(await HandleExceptionAsync(ex));
     }
 }
コード例 #3
0
 public async Task <IActionResult> Post([FromBody] contact_type entity)
 {
     try
     {
         if (!isValid(entity))
         {
             return(new BadRequestResult());                  // This returns HTTP 404
         }
         //sm(agent.Messages);
         return(Ok(await agent.Add <contact_type>(entity)));
     }
     catch (Exception ex)
     {
         //sm(agent.Messages);
         return(await HandleExceptionAsync(ex));
     }
 }
コード例 #4
0
        public async Task Post()
        {
            //Arrange
            var entity = new contact_type()
            {
                type = "testPost"
            };


            //Act
            var response = await controller.Post(entity);

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(response);
            var result   = Assert.IsType <contact_type>(okResult.Value);


            Assert.Equal("testPost", result.type);
        }
コード例 #5
0
        public void deleteItem(object item)
        {
            if (item == null)
            {
                return;
            }

            contact_type data = item as contact_type;

            if (data == null)
            {
                return;
            }

            using (var db = new PlanningContext())
            {
                db.contact_type.Remove(db.contact_type.Where(d => d.contact_type_id == data.contact_type_id).First());
                db.SaveChanges();
            }
        }
コード例 #6
0
        public async Task Put()
        {
            //Arrange
            var get = await controller.Get(1);

            var okgetResult = Assert.IsType <OkObjectResult>(get);
            var entity      = Assert.IsType <contact_type>(okgetResult.Value);
            var newEntity   = new contact_type();

            newEntity.type = "deployed Staff";
            //should test the equals Equatable for all these too
            var huh = entity.Equals(newEntity);
            //Act
            var response = await controller.Put(1, entity);

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(response);
            var result   = Assert.IsType <contact_type>(okResult.Value);

            Assert.Equal(entity.type, result.type);
        }