示例#1
0
        public IHttpActionResult GetTargets(Guid projectId, Guid achievement)
        {
            var achievements = UnitOfWork.DataListsRepository.FindIncluding(AchievementDataListId, d => d.AllItems);
            var targets      = UnitOfWork.FormValuesRepository.AllIncludingNoTracking(fv => fv.FilledForm)
                               .Where(fv => fv.FilledForm.ProjectId == projectId && fv.MetricId == TargetAchievementIdMetricId)
                               .Where(fv => achievement == null || (fv.GuidValue == achievement && fv.BoolValue == true))
                               .Select(fv => fv.FilledForm)
                               .Distinct()
                               .ToList()
                               .Select(filledForm => TargetDTO.From(filledForm));

            return(Ok(targets));
        }
示例#2
0
        public IHttpActionResult GetTargets(Guid projectId)
        {
            var today = DateTime.Today;

            var targetsform = UnitOfWork.FilledFormsRepository
                              .AllIncludingNoTracking(f => f.FormValues)
                              .Where(t => t.ProjectId == projectId && t.FormTemplateId == TargetFormTemplateId)
                              .ToList();
            var targets = targetsform.Where(t => t.FormValues.FirstOrDefault(v => v.MetricId == TargetFormWeekDateMetricId).DateValue.Value.Date <= today.Date)
                          .Where(f => f.FormValues.FirstOrDefault(v => v.MetricId == TargetIsAchievedMetricId).GuidValue != IsAchievedDataListItemId)
                          .Select(filledForm => TargetDTO.From(filledForm));

            return(Ok(targets));
        }
        public static TargetEN Convert(TargetDTO dto)
        {
            TargetEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new TargetEN();



                    newinstance.Id = dto.Id;
                    if (dto.Goal_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IGoalCAD goalCAD = new MoSIoTGenNHibernate.CAD.MosIoT.GoalCAD();

                        newinstance.Goal = goalCAD.ReadOIDDefault(dto.Goal_oid);
                    }
                    newinstance.DesiredValue = dto.DesiredValue;
                    if (dto.Measure_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IMeasureCAD measureCAD = new MoSIoTGenNHibernate.CAD.MosIoT.MeasureCAD();

                        newinstance.Measure = measureCAD.ReadOIDDefault(dto.Measure_oid);
                    }
                    newinstance.Description = dto.Description;
                    newinstance.DueDate     = dto.DueDate;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
示例#4
0
        public HttpResponseMessage Modify(int idTarget, [FromBody] TargetDTO dto)
        {
            // CAD, CEN, returnValue
            TargetRESTCAD targetRESTCAD = null;
            TargetCEN     targetCEN     = null;
            TargetDTOA    returnValue   = null;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                targetRESTCAD = new TargetRESTCAD(session);
                targetCEN     = new TargetCEN(targetRESTCAD);

                // Modify
                targetCEN.Modify(idTarget,
                                 dto.DesiredValue
                                 ,
                                 dto.Description
                                 ,
                                 dto.DueDate
                                 );

                // Return modified object
                returnValue = TargetAssembler.Convert(targetRESTCAD.ReadOIDDefault(idTarget), session);

                SessionCommit();
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue);

                return(response);
            }
        }
示例#5
0
        public HttpResponseMessage New_([FromBody] TargetDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            TargetRESTCAD targetRESTCAD = null;
            TargetCEN     targetCEN     = null;
            TargetDTOA    returnValue   = null;
            int           returnOID     = -1;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                targetRESTCAD = new TargetRESTCAD(session);
                targetCEN     = new TargetCEN(targetRESTCAD);

                // Create
                returnOID = targetCEN.New_(

                    //Atributo OID: p_goal
                    // attr.estaRelacionado: true
                    dto.Goal_oid                     // association role

                    , dto.DesiredValue               //Atributo Primitivo: p_desiredValue
                    , dto.Description                //Atributo Primitivo: p_description
                    , dto.DueDate                    //Atributo Primitivo: p_dueDate
                    );
                SessionCommit();

                // Convert return
                returnValue = TargetAssembler.Convert(targetRESTCAD.ReadOIDDefault(returnOID), session);
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 201 - Created
            response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue);

            // Location Header

            /*
             * Dictionary<string, object> routeValues = new Dictionary<string, object>();
             *
             * // TODO: y rolPaths
             * routeValues.Add("id", returnOID);
             *
             * uri = Url.Link("GetOIDTarget", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
示例#6
0
 public Target Map(TargetDTO dto)
 {
     if (dto == null) return null;
     var target = Mapper.Map<TargetDTO, Target>(dto);
     target.CostCentre = _costCentreRepository.GetById(dto.CostCentreId);
     target.TargetPeriod = _targetPeriodRepository.GetById(dto.TargetPeriodMasterId);
     return target;
 }