public IHttpActionResult Get(int id)
 {
     //string accessType = "PO_ViewAll";
     //ThrowIfUserHasNoRole(accessType);
     using (POQuery poQuery = new POQuery(Db))
     {
         var data = poQuery.GetByPrimaryKey(id);
         SaveLog("PO", "Get", JsonConvert.SerializeObject(new { primaryKey = id }));
         return(Ok(new SuccessResponse(data)));
     }
 }
        public List <SaveResult <PODTO> > GetSaveResults(List <PODTO> poList, DateTime dateStamp)
        {
            var validationResults = Validate(poList);
            List <SaveResult <PODTO> > saveResults = new List <SaveResult <PODTO> >();

            foreach (var validationResult in validationResults)
            {
                var poDTO = (PODTO)validationResult.GetModel();
                if (validationResult.IsValid)
                {
                    var exists = poQuery.GetByPrimaryKey(poDTO.PO_PK);
                    if (poDTO.PO_PK > 0 && exists != null)
                    {
                        UpdatePO(poDTO, dateStamp);
                    }
                    else
                    {
                        poDTO.PO_PK = 0;
                        AddPO(poDTO, dateStamp);
                    }

                    var saveResult = new SaveResult <PODTO>()
                    {
                        Message          = "SUCCESS",
                        Model            = poDTO,
                        Success          = true,
                        ValidationResult = validationResult,
                    };
                    saveResults.Add(saveResult);
                }
                else
                {
                    var saveResult = new SaveResult <PODTO>()
                    {
                        Message          = "FAILED",
                        Model            = poDTO,
                        Success          = false,
                        ValidationResult = validationResult,
                    };
                    saveResults.Add(saveResult);
                }
            }
            return(saveResults);
        }
Example #3
0
        private POEntryModel GetUpdateStateModel(int po_PK)
        {
            POEntryFormData formData = new POEntryFormData();

            PODTO pODTO = POQuery.GetByPrimaryKey(po_PK);

            if (pODTO == null)
            {
                throw new KairosException($"Record with primary key '{po_PK}' is not found.");
            }



            return(new POEntryModel()
            {
                FormData = formData,
                Model = pODTO
            });
        }