Example #1
0
 public IActionResult Create([Bind("Name,Id")] ClassificationDTO classificationDTO)
 {
     if (ModelState.IsValid)
     {
         _classificationApp.Insert(classificationDTO);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(classificationDTO));
 }
Example #2
0
 public static T ToDraft <T>(this ClassificationDTO source)
     where T : class, IClassification
 {
     if (source == null)
     {
         return(null);
     }
     return((T)Activator.CreateInstance(typeof(T), source));
 }
Example #3
0
        public IActionResult Edit(int id, [Bind("Name,Id")] ClassificationDTO classificationDTO)
        {
            if (id != classificationDTO.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _classificationApp.Update(classificationDTO);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(classificationDTO));
        }
        public static ClassificationDTO SetDTO(Classification classification)
        {
            if (classification == null)
            {
                return(null);
            }

            ClassificationDTO classificationDTO = new ClassificationDTO();

            classificationDTO.Id       = classification.Id;
            classificationDTO.Position = classification.Position;

            classificationDTO.ShortStory = ShortStoryTranslator.SetDTO(classification.ShortStory);

            return(classificationDTO);
        }
Example #5
0
        private Dictionary <ClassificationDTO, List <UnitSelectionDTO> > AppendIfNotExist(
            Dictionary <ClassificationDTO, List <UnitSelectionDTO> > dictionary,
            ClassificationDTO key, UnitSelectionDTO unitSelectionDto)
        {
            if (dictionary.ContainsKey(key))
            {
                dictionary[key].Add(unitSelectionDto);
            }
            else
            {
                dictionary.Add(key, new List <UnitSelectionDTO>()
                {
                    unitSelectionDto
                });
            }

            return(dictionary);
        }
Example #6
0
        private UnitSelectionDTO FlatToHierarchy(List <DAL.Entities.Tables.UnitTree> list, List <int> expandableClassifications = null, int?topLevelId = null)
        {
            bool limited = expandableClassifications == null;

            foreach (var unitTree in list.Where(x => x.ParentId == topLevelId))
            {
                unitTree.ParentId = -1;
            }

            var lookup = new Dictionary <int, UnitSelectionDTO>()
            {
                { -1, new UnitSelectionDTO() }
            };

            foreach (var item in list)
            {
                UnitSelectionDTO unitSelectionDto = _mapper.Map <UnitSelectionDTO>(item);
                lookup.Add(item.Id, unitSelectionDto);
            }
            foreach (DAL.Entities.Tables.UnitTree item in list)
            {
                ClassificationDTO classification = _mapper.Map <ClassificationDTO>(item.UnitClassification);
                var parentGroup = lookup[item.ParentId.Value].Children;
                if (limited || expandableClassifications.Contains(item.UnitClassificationId))
                {
                    if (lookup.ContainsKey(item.ParentId.Value))
                    {
                        AppendIfNotExist(parentGroup, classification, lookup[item.Id]);
                    }
                }
                else if (!parentGroup.ContainsKey(classification))
                {
                    parentGroup.Add(classification, new List <UnitSelectionDTO>());
                }
            }

            foreach (var unitTree in lookup.Where(x => x.Value.ParentId == -1))
            {
                unitTree.Value.ParentId = topLevelId;
            }

            return(lookup[-1]);
        }
Example #7
0
        public ProcessResponseDTO ProcessPipeline(ClassificationDTO data)
        {
            try
            {
                HttpStatusCode    statusCode;
                ProcessRequestDTO postObj = data.docs;
                postObj.client = data.docs.client;

                // JavaScriptSerializer req_serializer = new JavaScriptSerializer();
                //req_serializer.MaxJsonLength = Int32.MaxValue;
                var json = JsonConvert.SerializeObject(postObj);

                //var json = new JavaScriptSerializer().Serialize(postObj);
                string respone = MakeHttpPostRequest(data.access.PythonServiceBaseURL + "/prediction_service/process_pipeline", json, out statusCode);

                //Logger.Info("Response Received");

                //JavaScriptSerializer serializer = new JavaScriptSerializer();
                //serializer.MaxJsonLength = Int32.MaxValue;
                EncodedProcessResponseDTO resObj = (EncodedProcessResponseDTO)JsonConvert.DeserializeObject(respone, typeof(EncodedProcessResponseDTO));

                //Logger.Info("Deserialized");

                var    sOutput = new MemoryStream();
                string text;
                byte[] gzBuffer = Convert.FromBase64String(resObj.response);
                using (var ms = new MemoryStream())
                {
                    ms.Write(gzBuffer, 0, gzBuffer.Length);
                    var buffer = new byte[ms.Length * 1024];
                    ms.Position = 0;
                    using (var infS = new ZlibStream(ms, Ionic.Zlib.CompressionMode.Decompress))
                    {
                        infS.Read(buffer, 0, buffer.Length);
                        //infS.CopyTo(sOutput);
                    }
                    text = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                }

                text = text.TrimEnd('\0');
                ProcessResponseDTO responseObj = (ProcessResponseDTO)JsonConvert.DeserializeObject(text, typeof(ProcessResponseDTO));
                //Logger.Info("Decoded data =>" + responseObj);
                if (statusCode != HttpStatusCode.OK)
                {
                    throw new Exception("Web request failure during process pipeline. Status Code:" + statusCode.ToString());
                }
                else if (responseObj.message == "Token is valid but Expired, Please generate request to get new token")
                {
                    //tokenResult tr = Authorization(pythonBasedURL, User, Password);
                    //docs.token = tr.token;
                    //ProcessResponseDTO responseObj1 = ProcessPipeline(docs, pythonBasedURL, User, Password);
                    //return responseObj1;
                }
                else if (!responseObj.status.Equals("success"))
                {
                    throw new Exception(responseObj.message);
                }


                return(responseObj);
            }
            catch (Exception ex)
            {
                //Logger.Info(ex.Message);
            }
            return(new ProcessResponseDTO());
        }