public IHttpActionResult CreateRewardPkg(int id, RewardPkgDTO newRewardPkgs) { var rewardPkg = new RewardPkgDTO(); try { if (!ModelState.IsValid) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.BAD_REQUEST }); } // Check authen. if (User.Identity == null || !User.Identity.IsAuthenticated) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.NOT_AUTHEN }); } rewardPkg = ProjectRepository.Instance.CreateRewardPkg(id, newRewardPkgs, User.Identity.Name); } catch (Exception) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.BAD_REQUEST }); } return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.SUCCESS, Message = "", Type = "", Data = rewardPkg }); }
public IHttpActionResult EditRewardPkg(RewardPkgDTO rewardPkg) { bool result = false; try { // Check authen. if (User.Identity == null || !User.Identity.IsAuthenticated) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.NOT_AUTHEN }); } if (rewardPkg == null) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.BAD_REQUEST }); } result = ProjectRepository.Instance.EditRewardPkg(rewardPkg, User.Identity.Name); } catch (KeyNotFoundException) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.NOT_FOUND }); } catch (NotPermissionException) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.NOT_AUTHEN }); } catch (Exception) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.BAD_REQUEST }); } return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.SUCCESS, Message = "", Type = "" }); }