Beispiel #1
0
        public async Task <ResponseModel> Delete(EthnicityModel model)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                Ethnicity md = await _context.NationRepository.FirstOrDefaultAsync(m => m.Id == model.Id);

                if (!md.RowVersion.SequenceEqual(model.RowVersion))
                {
                    response.ResponseStatus = Core.CommonModel.Enums.ResponseStatus.OutOfDateData;
                    return(response);
                }

                md.Deleted    = true;
                md.UpdateBy   = base.UserId;
                md.UpdateDate = DateTime.Now;

                _context.NationRepository.Update(md);

                await _context.SaveChangesAsync();

                _memoryCachingService.Remove(CacheKey);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(response);
        }
Beispiel #2
0
        public async Task <ResponseModel> Insert(EthnicityModel model)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                Ethnicity md = new Ethnicity();

                md.Name       = model.Name;
                md.Precedence = model.Precedence;
                md.IsActive   = model.IsActive;
                md.CreateBy   = base.UserId;
                md.CreateDate = DateTime.Now;
                md.Deleted    = false;

                await _context.NationRepository.AddAsync(md).ConfigureAwait(true);

                await _context.SaveChangesAsync();

                _memoryCachingService.Remove(CacheKey);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(response);
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            EthnicityModel ethnicityModel = await db.EthnicityModel.FindAsync(id);

            db.EthnicityModel.Remove(ethnicityModel);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "EthnicityId,Ethnicity")] EthnicityModel ethnicityModel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ethnicityModel).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(ethnicityModel));
        }
        public async Task <ActionResult> Create([Bind(Include = "EthnicityId,Ethnicity")] EthnicityModel ethnicityModel)
        {
            if (ModelState.IsValid)
            {
                db.EthnicityModel.Add(ethnicityModel);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(ethnicityModel));
        }
        public async Task <ActionResult> Put([FromBody] EthnicityModel value)
        {
            try
            {
                await _repository.UpdateAsync(value);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
        public async Task <ActionResult <EthnicityModel> > Post([FromBody] EthnicityModel value)
        {
            try
            {
                var result = await _repository.CreateAsync(value);

                return(CreatedAtAction(nameof(Get), new { id = result.Id }, result));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Beispiel #8
0
        public async Task Get_NotFound()
        {
            // arrange
            var model = new EthnicityModel();

            _repository.Setup(x => x.GetAsync(It.IsAny <int>())).Returns(Task.FromResult((EthnicityModel)null));

            // act
            var result = await _controller.Get(1);

            // assert
            _repository.Verify(x => x.GetAsync(1), Times.Once);
            Assert.IsType <NotFoundResult>(result.Result);
        }
Beispiel #9
0
        public async Task Put()
        {
            // arrange
            var model = new EthnicityModel();

            _repository.Setup(x => x.UpdateAsync(It.IsAny <EthnicityModel>())).Returns(Task.FromResult(model));

            // act
            var result = await _controller.Put(model);

            // assert
            _repository.Verify(x => x.UpdateAsync(model), Times.Once);
            Assert.IsType <OkResult>(result);
        }
        // GET: EthnicityModels/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EthnicityModel ethnicityModel = await db.EthnicityModel.FindAsync(id);

            if (ethnicityModel == null)
            {
                return(HttpNotFound());
            }
            return(View(ethnicityModel));
        }
Beispiel #11
0
        public async Task Get()
        {
            // arrange
            var model = new EthnicityModel();

            _repository.Setup(x => x.GetAsync(It.IsAny <int>())).Returns(Task.FromResult(model));

            // act
            var result = await _controller.Get(1);

            // assert
            _repository.Verify(x => x.GetAsync(1), Times.Once);
            Assert.IsType <OkObjectResult>(result.Result);
            Assert.Same(model, (result.Result as OkObjectResult).Value);
        }
        /// <summary>
        /// To the view model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public static EthnicityViewModel ToViewModel(this EthnicityModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var entity = new EthnicityViewModel
            {
                EthnicityID = model.EthnicityID,
                Ethnicity   = model.Ethnicity
            };

            return(entity);
        }
        /// <summary>
        /// To the model.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static EthnicityModel ToModel(this EthnicityViewModel entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var model = new EthnicityModel
            {
                EthnicityID = entity.EthnicityID,
                Ethnicity   = entity.Ethnicity
            };

            return(model);
        }
Beispiel #14
0
        public async Task Post()
        {
            // arrange
            var model = new EthnicityModel {
                Id = 1
            };

            _repository.Setup(x => x.CreateAsync(It.IsAny <EthnicityModel>())).Returns(Task.FromResult(model));

            // act
            var result = await _controller.Post(model);

            // assert
            _repository.Verify(x => x.CreateAsync(model), Times.Once);
            Assert.Same(model, (result.Result as CreatedAtActionResult).Value);
        }
Beispiel #15
0
        public async Task Post()
        {
            // arrange
            var model = new EthnicityModel {
                Value = "teste"
            };

            // act
            var response = await _client.PostAsync(_address, new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"));

            // assert
            response.EnsureSuccessStatusCode();
            var result = JsonConvert.DeserializeObject <EthnicityModel>(await response.Content.ReadAsStringAsync());

            Assert.Equal(model.Value, result.Value);
            Assert.Equal(1, result.Id);
        }
Beispiel #16
0
        public async Task Get()
        {
            // arrange
            var model = new EthnicityModel {
                Id = 1, Value = "Teste"
            };

            _context.Ethnicities.Add(model);
            await _context.SaveChangesAsync();

            // act
            var response = await _client.GetAsync($"{_address}/1");

            // assert
            response.EnsureSuccessStatusCode();
            var result = JsonConvert.DeserializeObject <EthnicityModel>(await response.Content.ReadAsStringAsync());

            Assert.Equal(model.Id, result.Id);
            Assert.Equal(model.Value, result.Value);
        }
Beispiel #17
0
        public async Task Put()
        {
            // arrange
            var model = new EthnicityModel {
                Id = 4, Value = "Teste 4"
            };
            var newModel = new EthnicityModel {
                Id = 4, Value = "Novo Teste 4"
            };

            _context.Ethnicities.Add(model);
            await _context.SaveChangesAsync();

            // act
            var response = await _client.PutAsync(_address, new StringContent(JsonConvert.SerializeObject(newModel), Encoding.UTF8, "application/json"));

            _context.Entry(model).Reload();

            // assert
            response.EnsureSuccessStatusCode();
            Assert.Equal(newModel.Value, model.Value);
        }
        public async Task <ResponseModel> Delete([FromBody] EthnicityModel model)
        {
            var response = await _nationService.Delete(model);

            return(response);
        }