public IHttpActionResult UpdateCountry(CountryModel model) { var response = new DataResponse <EntityCountry>(); if (ModelState.IsValid) { var entityCountry = new EntityCountry(); entityCountry.Id = model.Id; entityCountry.CountryName = model.CountryName; entityCountry.CountryCode = model.CountryCode; entityCountry.IsActive = model.IsActive; entityCountry.UpdatedBy = CurrentUserId; entityCountry.UpdatedOn = System.DateTime.UtcNow; response = repository.UpdateCountry(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 })); } }
public DataResponse <EntityCountry> UpdateCountry(EntityCountry entity) { var response = new DataResponse <EntityCountry>(); try { base.DBInit(); var model = DBEntity.LookupCountries.FirstOrDefault(a => a.Id == entity.Id); model.CountryName = entity.CountryName; model.CountryCode = entity.CountryCode; model.IsActive = entity.IsActive; model.UpdatedOn = entity.UpdatedOn; model.UpdatedBy = entity.UpdatedBy; if (base.DBSaveUpdate(model) > 0) { return(GetCountryById(model.Id)); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); } finally { base.DBClose(); } return(response); }
public int DeleteCountry(EntityCountry entCountry) { int cnt = 0; try { List <SqlParameter> lstParam = new List <SqlParameter>(); Commons.ADDParameter(ref lstParam, "@CountryCode", DbType.String, entCountry.CountryCode); cnt = mobjDataAcces.ExecuteQuery("sp_DeleteCountry", lstParam); } catch (Exception ex) { Commons.FileLog("CountryBLL - DeleteCountry(EntityCountry entCountry)", ex); } return(cnt); }
public DataResponse <EntityCountry> Insert(EntityCountry entity) { var response = new DataResponse <EntityCountry>(); try { base.DBInit(); var model = new Database.LookupCountry { CountryName = entity.CountryName, CountryCode = entity.CountryCode, CreatedBy = entity.CreatedBy, CreatedOn = System.DateTime.UtcNow, IsActive = entity.IsActive }; if (base.DBSave(model) > 0) { entity.Id = model.Id; response.CreateResponse(entity, DataResponseStatus.OK); } else { response.CreateResponse(DataResponseStatus.InternalServerError); } } catch (Exception ex) { ex.Log(); response.ThrowError(ex); } finally { base.DBClose(); } return(response); }