public string EditTube(DtoTube dtoTube) { var uniqeTube = TubeMethods.Instance.GetTubeByCode(dtoTube.Code); if (!dtoTube.IsEdit) { var tube = new Tube() { Code = dtoTube.Code, Name = dtoTube.Name, Volume = dtoTube.Volume }; return TubeMethods.Instance.InsertTube(tube); } else { var tube = new Tube() { Id = TubeMethods.Instance.GetTubeByCode(dtoTube.Code).Id, Code = dtoTube.Code, Name = dtoTube.Name, Volume = dtoTube.Volume }; return TubeMethods.Instance.UpdateTube(tube); } }
public static void ValidateTube(Tube tube) { if (string.IsNullOrEmpty(tube.Code) || string.IsNullOrEmpty(tube.Name)) { throw new TubeMandatoryFieldsException(); } else { if (tube.Volume > 1000) { throw new TubeVolumeException(); } } }
public string UpdateTube(Tube tube) { try { ValidateTube(tube); UpdateTubeEntity <Tube>(tube); string message = string.Format("Tube {0} updated", tube.Code); log.Info(message); return("c"); } catch (TubeException e) { log.Error(string.Format("Error saving Tube with Code = {0}, ErrorMessage: {1}", tube.Code, e.Message)); return(e.Message); } catch (GenericADOException e) { log.Error(string.Format("Error saving Tube with Code = {0}, ErrorMessage: not UNIQUE Code {0}/{1}", tube.Code, e.Message)); return("Code will be UNIQUE!"); } }
public string InsertTube(Tube tube) { try { ValidateTube(tube); InsertTubeEntity<Tube>(tube); string message = string.Format("Tube {0} saved", tube.Code); log.Info(message); return "s"; } catch (TubeException e) { log.Error(string.Format ("Error saving Tube with Code = {0}, ErrorMessage: {1}",tube.Code,e.Message)); return e.Message; } catch (GenericADOException e) { log.Error(string.Format("Error saving Tube with Code = {0}, ErrorMessage: not UNIQUE Code {0}/{1}", tube.Code, e.Message)); return "Code will be UNIQUE!"; } }
public void ValidateTube_VolumeException() { var tube = new Tube() { Code = "code", Name = "name", Volume = 1001 }; bool isExceptionExist = false; try { TubeMethods.ValidateTube(tube); } catch (Exception) { isExceptionExist = true; } Assert.IsTrue(isExceptionExist); ; }