예제 #1
0
        public int UpdateTemplate(StockTemplate template)
        {
            int userId = LoginManager.Instance.GetUserId();

            if (_permissionManager.HasPermission(userId, template.TemplateId, ResourceType.SpotTemplate, PermissionMask.Edit))
            {
                var dbItem = ConvertToDBItem(template);
                int tempId = _tempdbdao.Update(dbItem);
                if (tempId > 0)
                {
                    //add the usage tracking
                    _userActionTrackingBLL.Create(userId, Model.UsageTracking.ActionType.Edit, ResourceType.SpotTemplate, template.TemplateId, 1, Model.UsageTracking.ActionStatus.Success, JsonUtil.SerializeObject(template));

                    //update the permission
                    foreach (var perm in template.Permissions)
                    {
                        bool isUpdated = (perm.Id > 0) ? true : false;
                        _permissionManager.ChangePermission(perm.Token, template.TemplateId, ResourceType.SpotTemplate, perm.Permission, isUpdated);
                    }

                    return(tempId);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                return(-1);
            }
        }
예제 #2
0
        public StockTemplate CreateTemplate(StockTemplate template)
        {
            var dbItem     = ConvertToDBItem(template);
            int templateId = _tempdbdao.Create(dbItem);

            if (templateId > 0)
            {
                template.TemplateId = templateId;
                int userId = LoginManager.Instance.GetUserId();

                //Add the usage tracking information
                _userActionTrackingBLL.Create(userId, Model.UsageTracking.ActionType.Create, ResourceType.SpotTemplate, templateId, 1, Model.UsageTracking.ActionStatus.Success, JsonUtil.SerializeObject(template));

                var perms = _permissionManager.GetOwnerPermission();
                _permissionManager.GrantPermission(userId, templateId, ResourceType.SpotTemplate, perms);

                foreach (var perm in template.Permissions)
                {
                    if (perm.Token != userId)
                    {
                        bool isUpdated = (perm.Id > 0) ? true : false;
                        _permissionManager.ChangePermission(perm.Token, template.TemplateId, ResourceType.SpotTemplate, perm.Permission, isUpdated);
                    }
                }
            }

            return(template);
        }
예제 #3
0
        public int ArchiveTemplate(StockTemplate template)
        {
            ArchiveStockTemplate hst = new ArchiveStockTemplate(template);

            hst.DArchiveDate = DateTime.Now;

            int archiveId = -1;
            var stocks    = _stockdbdao.Get(template.TemplateId);

            if (stocks != null)
            {
                archiveId = _templatedao.Archive(hst, stocks);
                if (archiveId > 0)
                {
                    //add permission
                    foreach (var perm in hst.Permissions)
                    {
                        _permissionManager.ChangePermission(perm.Token, archiveId, Model.Permission.ResourceType.HistoricalSpotTemplate, perm.Permission, false);
                    }
                }
                else
                {
                    archiveId = -1;
                }
            }

            return(archiveId);
        }
예제 #4
0
        public int CreateTemplate(StockTemplate template)
        {
            HistStockTemplate hst = new HistStockTemplate(template);

            hst.DArchiveDate = DateTime.Now;

            int archiveId = _templatedao.Create(hst);

            if (archiveId > 0)
            {
                //add permission
                foreach (var perm in hst.Permissions)
                {
                    _permissionManager.ChangePermission(perm.Token, archiveId, Model.Permission.ResourceType.HistoricalSpotTemplate, perm.Permission, false);
                }
            }
            else
            {
                archiveId = -1;
            }

            return(archiveId);
        }