Esempio n. 1
0
        public IHttpActionResult CreateCountry(CountryModel model)
        {
            var response = new DataResponse <EntityCountry>();

            if (ModelState.IsValid)
            {
                var entityCountry = new EntityCountry();
                entityCountry.CountryName = model.CountryName;
                entityCountry.CountryCode = model.CountryCode;
                entityCountry.IsActive    = model.IsActive;
                entityCountry.CreatedBy   = CurrentUserId;
                response = repository.Insert(entityCountry);
                return(Ok <DataResponse>(response));
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
        }