public long Insert(BoatsCapacity card) { using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection)) { sqlConnection.Open(); var _boatsCapacity = new BoatsCapacity() { GUID = Guid.NewGuid().ToString(), RECORD_STATUS = 1, INSERT_DATE = DateTime.Now, INSERT_USER = card.INSERT_USER, UPDATE_DATE = DateTime.Now, UPDATE_USER = card.UPDATE_USER, RESERVATION_ID = card.RESERVATION_ID, BOAT_ID = card.BOAT_ID, RESERVATION_DATE = card.RESERVATION_DATE, RESERVATION_END_DATE = card.RESERVATION_END_DATE, CAPACITY = card.CAPACITY, }; var customerGuid = sqlConnection.Insert <BoatsCapacity>(_boatsCapacity); sqlConnection.Close(); return(customerGuid); } }
//Probably !!This method will not be use public bool Delete(BoatsCapacity request) { try { BoatsCapacity _boatsCapacity = null; using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection)) { sqlConnection.Open(); _boatsCapacity = sqlConnection.Get <BoatsCapacity>(request.BOAT_ID); _boatsCapacity.RECORD_STATUS = 0; _boatsCapacity.UPDATE_DATE = DateTime.Now; _boatsCapacity.UPDATE_USER = request.UPDATE_USER; sqlConnection.Update <BoatsCapacity>(_boatsCapacity); var result = sqlConnection.Get <BoatsCapacity>(_boatsCapacity.BOAT_ID); } return(true); } catch (Exception ex) { //log.Error("Delete BoatsCapacity has an ERROR: [ERROR : " + ex.Message + "]"); return(false); } }
public bool Update(BoatsCapacity request) { try { BoatsCapacity _boatCapacity = null; using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection)) { sqlConnection.Open(); IEnumerable <BoatsCapacity> boats_capacity = sqlConnection.Query <BoatsCapacity>("select * from BOATS_CAPACITY where BOAT_ID = @id and RESERVATION_DATE = @date and RECORD_STATUS = 1", new { id = request.BOAT_ID, date = request.RESERVATION_DATE }); if (boats_capacity.Count() == 0) { throw new Exception(CommonDefinitions.BOAT_NOT_FOUND); } else { _boatCapacity = boats_capacity.FirstOrDefault(); } _boatCapacity.RECORD_STATUS = 1; _boatCapacity.INSERT_DATE = request.INSERT_DATE; _boatCapacity.INSERT_USER = request.INSERT_USER; _boatCapacity.UPDATE_DATE = DateTime.Now; _boatCapacity.UPDATE_USER = request.UPDATE_USER; _boatCapacity.RESERVATION_ID = request.RESERVATION_ID; _boatCapacity.CAPACITY = request.CAPACITY; _boatCapacity.BOAT_ID = request.BOAT_ID; _boatCapacity.BOAT_CAPACITY_ID = request.BOAT_CAPACITY_ID; _boatCapacity.RESERVATION_DATE = request.RESERVATION_DATE; _boatCapacity.RESERVATION_END_DATE = request.RESERVATION_END_DATE; sqlConnection.Update <BoatsCapacity>(_boatCapacity); var result = sqlConnection.Get <BoatsCapacity>(_boatCapacity.BOAT_CAPACITY_ID); } return(true); } catch (Exception ex) { //log.Error("Update BoatsCapacity has an ERROR: [ERROR : " + ex.Message + "]"); return(false); } }
public BoatsCapacity SelectByBoatId(BoatsCapacity request) { BoatsCapacity _boatCapacity = null; using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection)) { sqlConnection.Open(); IEnumerable <BoatsCapacity> boats_capacity = sqlConnection.Query <BoatsCapacity>("select * from BOATS_CAPACITY where BOAT_ID = @id and RESERVATION_DATE = @date and RECORD_STATUS = 1", new { id = request.BOAT_ID, date = request.RESERVATION_DATE }); if (boats_capacity.Count() == 0) { boats_capacity = null; } //throw new Exception(CommonDefinitions.BOAT_NOT_FOUND); else { _boatCapacity = boats_capacity.FirstOrDefault(); } } return(_boatCapacity); }
public override void DoOperation() { //Validate Reques Header / Constants this.baseResponseMessage = ValidateInput(); if (!this.baseResponseMessage.header.IsSuccess) { throw new Exception(this.baseResponseMessage.header.ResponseMessage); } switch (this.request.Header.OperationTypes) { case (int)OperationType.OperationTypes.ADD: #region ADD Int32 capacity = 0; Boats boat = new Boats(); boat = Boats.SelectByBoatId(request.BOAT_ID); if (Convert.ToInt32(request.CAPACITY) < boat.QUANTITY) { capacity = boat.QUANTITY - Convert.ToInt32(request.CAPACITY); } else { throw new Exception(CommonDefinitions.BOAT_CAPACITY_IS_NOT_ENOUGH); } boatCapacity = new BoatsCapacity { BOAT_ID = request.BOAT_ID, CAPACITY = request.CAPACITY, RESERVATION_DATE = request.RESERVATION_DATE, RESERVATION_END_DATE = request.RESERVATION_END_DATE, RESERVATION_ID = request.RESERVATION_ID }; BoatsCapacity responseBoatsCapacity = new BoatsCapacity(); responseBoatsCapacity = BoatsCapacity.SelectByBoatId(boatCapacity); if (responseBoatsCapacity == null) { boatCapacity.CAPACITY = capacity.ToString(); boatCapacity.BOAT_CAPACITY_ID = BoatsCapacity.Insert(boatCapacity); } else { responseBoatsCapacity.RESERVATION_ID = boatCapacity.RESERVATION_ID; Int32 newCapactiy = Convert.ToInt32(response.CAPACITY) - Convert.ToInt32(boatCapacity.CAPACITY); if (newCapactiy < 0) { throw new Exception(CommonDefinitions.BOAT_CAPACITY_IS_NOT_ENOUGH); } else { response.CAPACITY = newCapactiy.ToString(); BoatsCapacity.Update(responseBoatsCapacity); } } this.response = new ResponseBoatCapacity { BOAT_ID = responseBoatsCapacity.BOAT_ID, CAPACITY = responseBoatsCapacity.CAPACITY, RESERVATION_DATE = responseBoatsCapacity.RESERVATION_DATE, RESERVATION_END_DATE = responseBoatsCapacity.RESERVATION_END_DATE, RESERVATION_ID = responseBoatsCapacity.RESERVATION_ID, BOAT_CAPACITY_ID = responseBoatsCapacity.BOAT_CAPACITY_ID, header = new ResponseHeader { IsSuccess = true, ResponseCode = CommonDefinitions.SUCCESS, ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE } }; #endregion break; case (int)OperationType.OperationTypes.GET: #region Get boatCapacity = new BoatsCapacity { BOAT_ID = request.BOAT_ID, CAPACITY = request.CAPACITY, RESERVATION_DATE = request.RESERVATION_DATE, RESERVATION_END_DATE = request.RESERVATION_END_DATE, RESERVATION_ID = request.RESERVATION_ID }; BoatsCapacity responseCapacity = new BoatsCapacity(); responseCapacity = BoatsCapacity.SelectByBoatId(boatCapacity); this.response = new ResponseBoatCapacity { BOAT_ID = responseCapacity.BOAT_ID, CAPACITY = responseCapacity.CAPACITY, RESERVATION_DATE = responseCapacity.RESERVATION_DATE, RESERVATION_END_DATE = responseCapacity.RESERVATION_END_DATE, RESERVATION_ID = responseCapacity.RESERVATION_ID, BOAT_CAPACITY_ID = responseCapacity.BOAT_CAPACITY_ID, header = new ResponseHeader { IsSuccess = true, ResponseCode = CommonDefinitions.SUCCESS, ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE } }; #endregion break; default: break; } }