Exemplo n.º 1
0
        public IHttpActionResult Patch(int id, [FromBody] PatientEntryModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var entity = new Patient
                    {
                        AccountId      = id,
                        FirstName      = model.FirstName,
                        LastName       = model.LastName,
                        BirthDate      = model.BirthDate.Value,
                        Status         = model.Status,
                        Gender         = model.Gender,
                        Telephone      = model.Telephone,
                        Address        = model.Address,
                        MedicareNumber = model.MedicareNumber
                    };

                    if (_repository.Update(entity, e => e.FirstName,
                                           e => e.FirstName,
                                           e => e.LastName,
                                           e => e.BirthDate,
                                           e => e.Status,
                                           e => e.Gender,
                                           e => e.Telephone,
                                           e => e.Address,
                                           e => e.MedicareNumber))
                    {
                        _repository.Commit();
                    }
                    else
                    {
                        return(base.BadRequest("Cannot update Patient " + entity.AccountId));
                    }

                    return(base.Ok());
                }
                else
                {
                    return(base.BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                return(base.BadRequest(ex.Message));
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult Post([FromBody] PatientEntryModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var entity = new Patient
                    {
                        Account = new Account
                        {
                            Username     = model.Username,
                            Password     = model.Password,
                            Email        = model.Email,
                            CreationDate = DateTime.Now
                        },
                        FirstName      = model.FirstName,
                        LastName       = model.LastName,
                        BirthDate      = model.BirthDate.Value,
                        Status         = model.Status,
                        Gender         = model.Gender,
                        Telephone      = model.Telephone,
                        Address        = model.Address,
                        MedicareNumber = model.MedicareNumber
                    };

                    _repository.Add(entity);
                    _repository.Commit();

                    model.AccountId = entity.AccountId;

                    return(base.Ok(model));
                }
                else
                {
                    return(base.BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                return(base.BadRequest(ex.Message));
            }
        }