public long AddCountry(StoreCountryObject country) { try { if (country == null) { return(-2); } var duplicates = _repository.Count(m => m.Name.Trim().ToLower() == country.Name.Trim().ToLower() && (m.StoreCountryId != country.StoreCountryId)); if (duplicates > 0) { return(-3); } var countryEntity = ModelCrossMapper.Map <StoreCountryObject, StoreCountry>(country); if (countryEntity == null || string.IsNullOrEmpty(countryEntity.Name)) { return(-2); } var returnStatus = _repository.Add(countryEntity); _uoWork.SaveChanges(); return(returnStatus.StoreCountryId); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int UpdateCountry(StoreCountryObject country) { try { if (country == null) { return(-2); } var duplicates = _repository.Count(m => m.Name.Trim().ToLower() == country.Name.Trim().ToLower() && (m.StoreCountryId != country.StoreCountryId)); if (duplicates > 0) { return(-3); } var countryEntity = ModelCrossMapper.Map <StoreCountryObject, StoreCountry>(country); if (countryEntity == null || countryEntity.StoreCountryId < 1) { return(-2); } _repository.Update(countryEntity); _uoWork.SaveChanges(); return(5); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(-2); } }
public ActionResult EditCountry(StoreCountryObject country) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateCountry(country); if (valStatus.Code < 1) { gVal.Code = -1; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } if (Session["_country"] == null) { gVal.Code = -5; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var oldCountry = Session["_country"] as StoreCountryObject; if (oldCountry == null || oldCountry.StoreCountryId < 1) { gVal.Code = -5; gVal.Error = message_Feedback.Session_Time_Out; return(Json(gVal, JsonRequestBehavior.AllowGet)); } oldCountry.Name = country.Name.Trim(); var k = new CountryServices().UpdateCountry(oldCountry); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = k; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -5; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = 0; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }
public int UpdateCountry(StoreCountryObject country) { try { return(_countryRepository.UpdateCountry(country)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(-2); } }
public long AddCountry(StoreCountryObject countryAccount) { try { return(_countryRepository.AddCountry(countryAccount)); } catch (Exception ex) { ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
private GenericValidator ValidateCountry(StoreCountryObject country) { var gVal = new GenericValidator(); if (country == null) { gVal.Code = -1; gVal.Error = message_Feedback.Fatal_Error; return(gVal); } if (string.IsNullOrEmpty(country.Name)) { gVal.Code = -1; gVal.Error = message_Feedback.Country_Name_Error; return(gVal); } gVal.Code = 5; return(gVal); }
public ActionResult AddCountry(StoreCountryObject country) { var gVal = new GenericValidator(); try { if (ModelState.IsValid) { var valStatus = ValidateCountry(country); if (valStatus.Code < 1) { gVal.Code = -1; gVal.Error = valStatus.Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } var k = new CountryServices().AddCountry(country); if (k < 1) { gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Insertion_Failure; gVal.Code = 0; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = k; gVal.Error = message_Feedback.Insertion_Success; return(Json(gVal, JsonRequestBehavior.AllowGet)); } gVal.Code = -5; gVal.Error = message_Feedback.Model_State_Error; return(Json(gVal, JsonRequestBehavior.AllowGet)); } catch { gVal.Code = 0; gVal.Error = message_Feedback.Process_Failed; return(Json(gVal, JsonRequestBehavior.AllowGet)); } }