Exemplo n.º 1
0
        public ActionResult Custom(Guid?entityId)
        {
            SpreadSheetModel spreadSheetModel = new SpreadSheetModel();

            if (entityId != null && entityId.HasValue)
            {
                IOrganizationService             orgSerivce = CreateOrganizationService();
                CrmServiceContext                context    = new CrmServiceContext(orgSerivce);
                new_project_initiative_valuation valuation  = null;
                Annotation annotation = GetAnnotation(context, entityId, out valuation);
                spreadSheetModel.IsReadOnly = valuation != null && valuation.StatusCodeEnum == new_project_initiative_valuation_StatusCode.Neaktivnye;
                spreadSheetModel.Body       = SpreadsheetExtension.GetCurrentDocument("SpreadSheetEditor").SaveDocument(DocumentFormat.Xlsx);
                string documentBody = Convert.ToBase64String(spreadSheetModel.Body);
                if (annotation == null)
                {
                    orgSerivce.Create(new Annotation()
                    {
                        ObjectId       = new EntityReference(new_project_initiative_valuation.EntityLogicalName, entityId.Value),
                        ObjectTypeCode = new_project_initiative_valuation.EntityLogicalName,
                        MimeType       = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                        FileName       = "[Project Calculation].xlsx",
                        DocumentBody   = documentBody
                    });
                }
                else
                {
                    annotation.DocumentBody = documentBody;
                    context.UpdateObject(annotation);
                    context.SaveChanges();
                }
            }
            return(PartialView("SpreadSheetPartial", spreadSheetModel));
        }
Exemplo n.º 2
0
        public ActionResult Index(Guid?entityId)
        {
            IOrganizationService             orgSerivce = CreateOrganizationService();
            CrmServiceContext                context    = new CrmServiceContext(orgSerivce);
            new_project_initiative_valuation valuation  = null;
            Annotation annotation = GetAnnotation(context, entityId, out valuation);

            annotation = annotation ?? GetDefaultSettingAnnotation(context);
            SpreadSheetModel spreadSheetModel = new SpreadSheetModel()
            {
                Body       = GetAnnotationBody(orgSerivce, annotation),
                IsReadOnly = valuation != null && valuation.StatusCodeEnum == new_project_initiative_valuation_StatusCode.Neaktivnye
            };

            return(View(spreadSheetModel));
        }