public async Task <IHttpActionResult> Delete(int id) { try { string errorMessage = "UnknowError"; string errorCode = ErrorCodeEnum.UnknownError.ToString(); #region token var header = Request.Headers; if (header.Authorization == null) { return(StatusCode(HttpStatusCode.Unauthorized)); } var token = header.Authorization.Parameter; Employee employee; if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out employee)) { return(StatusCode(HttpStatusCode.Unauthorized)); } #endregion #region Check exist var obj = MemoryInfo.GetImage(id); if (obj == null) { return(Ok(new RequestErrorCode(false, ErrorCodeEnum.DataNotExist.ToString(), "Khong ton tai"))); } #endregion // check role if (!Operator.IsAdmin(employee)) { return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_NotHavePermision.ToString(), "Khong co quyen xoa"))); } #region Process UpdateEntitySql updateEntitySql = new UpdateEntitySql(); var lstCommand = new List <EntityCommand>(); lstCommand.Add(new EntityCommand { BaseEntity = new Entity(obj), EntityAction = EntityAction.Delete }); bool isOkDone = updateEntitySql.UpdateDefault(lstCommand); if (!isOkDone) { return(Ok(new RequestErrorCode(false, errorCode, errorMessage))); } #endregion var result = new RequestErrorCode(true); return(Ok(result)); } catch (Exception ex) { Logger.Write(ex.ToString()); } return(BadRequest("Unknow")); }
public static List <Image> GetImagesUrl(string lstImagesIdString) { var lstResult = new List <Image>(); try { String[] spearator = { "," }; // using the method String[] lstImagesId = lstImagesIdString.Split(spearator, StringSplitOptions.RemoveEmptyEntries); foreach (String imgIdString in lstImagesId) { //parse ve int int imagesId = 0; if (!Int32.TryParse(imgIdString, out imagesId)) { continue; } // lay imagesObject var imagesObj = MemoryInfo.GetImage(imagesId); if (imagesObj == null) { continue; } imagesObj.ImageUrl = AppGlobal.ElectricConfig.BaseUrl + imagesObj.ImageUrl; lstResult.Add(imagesObj); } return(lstResult); } catch (Exception ex) { Logger.Write("Co loi trong qua trinh get ImagesUrl"); } return(lstResult); }