Ejemplo n.º 1
0
        public JsonResult Disable(int id)
        {
            using (Entity context = new Entity())
            {
                try
                {
                    t_aim aim = context.t_aim.Find(id);
                    if (aim == null)
                    {
                        throw new ArgumentException("Invalid aimId: " + id.ToString());
                    }

                    aim.active           = false;
                    aim.updatedby_userid = CurrentUser.Id;
                    aim.updated_date     = DateTime.Now;
                    context.SaveChanges();

                    return(Json(new { success = true, Active = false, Status = common.InactiveStatus }));
                }
                catch (Exception ex)
                {
                    return(GetJsonResult(ex));
                }
            }
        }
Ejemplo n.º 2
0
 public Request(t_aim entity) : this(entity, false)
 {
     ObjectType = RequestObjectType.Aim;
     ObjectId   = entity.aim_id;
     Name       = entity.get_name_translated(IidCulture.CurrentLanguageId);
     Status     = SetStatus(entity.active);
 }
Ejemplo n.º 3
0
 private JsonResult GetSortResult(t_aim aim1, t_aim aim2)
 {
     return(Json(new
     {
         Aim1 = new { Id = aim1.aim_id, Sort = aim1.sort },
         Aim2 = new { Id = aim2?.aim_id, Sort = aim2?.sort }
     }));
 }
Ejemplo n.º 4
0
        public Aim(int aimId, bool loadChildren)
        {
            t_aim aim = Context.t_aim.Find(aimId);

            if (aim == null)
            {
                throw new ArgumentException("Invalid aimId: " + aimId.ToString());
            }

            SetProperties(aim, loadChildren, true);
        }
Ejemplo n.º 5
0
 private JsonResult GetJsonResult(t_aim aim)
 {
     return(Json(new
     {
         success = true,
         ActivityId = aim.activity_id,
         AimId = aim.aim_id,
         Name = aim.get_name_translated(IidCulture.CurrentLanguageId),
         Active = aim.active,
         Status = aim.active.HasValue ? (aim.active.Value ? common.ActiveStatus : common.InactiveStatus) : common.PendingStatus
     }));
 }
Ejemplo n.º 6
0
        private t_aim SetCoreFields(Aim model)
        {
            using (Entity context = new Entity())
            {
                t_aim aim = null;
                if (model.AimId.HasValue)
                {
                    aim = context.t_aim.Find(model.AimId.Value);
                    if (aim == null)
                    {
                        throw new ArgumentException("Invalid aimId: " + model.AimId.ToString());
                    }
                    aim.updatedby_userid = CurrentUser.Id;
                    aim.updated_date     = DateTime.Now;
                }
                else
                {
                    aim = new t_aim();
                    aim.createdby_userid = CurrentUser.Id;
                    aim.created_date     = DateTime.Now;

                    byte maxSort  = 0;
                    var  activity = context.t_activity.Find(model.ActivityId);
                    if (activity.aims.Count > 0)
                    {
                        maxSort = activity.aims.Max(e => e.sort);
                    }
                    aim.sort = maxSort += 1;

                    context.t_aim.Add(aim);
                }

                var language = IidCulture.CurrentLanguage;

                aim.activity_id = model.ActivityId;
                if (language == Language.English || !model.AimId.HasValue)
                {
                    aim.name = model.Name;
                }
                aim.active = model.Active;
                context.SaveChanges();

                if (language != Language.English)
                {
                    var languageId = IidCulture.CurrentLanguageId;
                    var userId     = CurrentUser.Id;
                    aim.set_name_translated(languageId, model.Name, userId);
                }

                return(aim);
            }
        }
Ejemplo n.º 7
0
        private void SetProperties(t_aim aim, bool loadChildren, bool translate)
        {
            ActivityId = aim.activity_id;
            AimId      = aim.aim_id;
            Active     = aim.active;
            Sort       = aim.sort;

            if (translate)
            {
                Name = aim.get_name_translated(CurrentLanguageId);
            }
            else
            {
                Name = aim.name;
            }

            if (loadChildren)
            {
                ActivityAims = UserAssignedObjects.GetAims(aim.activity.aims, CurrentUser).ToDictionary(e => e.aim_id, e => e.get_name_translated(CurrentLanguageId));
                Indicators   = UserAssignedObjects.GetIndicators(aim.indicators, CurrentUser).Select(i => new Indicator(i, false, true)).ToList();
            }
        }
Ejemplo n.º 8
0
        public JsonResult Delete(int id)
        {
            using (Entity context = new Entity())
            {
                try
                {
                    t_aim aim = context.t_aim.Find(id);
                    if (aim == null)
                    {
                        throw new ArgumentException("Invalid aimId: " + id.ToString());
                    }

                    context.t_aim.Remove(aim);
                    context.SaveChanges();

                    return(Json(new { success = true }));
                }
                catch (Exception ex)
                {
                    return(GetJsonResult(ex));
                }
            }
        }
Ejemplo n.º 9
0
 public Aim(t_aim aim, bool loadChildren, bool translate)
 {
     SetProperties(aim, loadChildren, translate);
 }