private IRestResponse DeleteMapRequestResponseFunc(IRestRequest request) { var response = new CoriaRestResponse(); Guid id; bool deleted; try { if (!Guid.TryParse(request.PathParameters["mapId"].ToString(), out id)) { throw new ArgumentException("Map ID is required."); } AdditionalInfo additionalInfo = PublicApi.Maps.Delete(id); deleted = additionalInfo.HasErrors(); if (deleted) { response.Data = "Map deleted."; } else { response.Data = "Map failed to delete."; IList <Error> ers = additionalInfo.Errors;// new List<Error>(); IList <string> s = new List <string>(); ers.ToList().ForEach(e => s.Add(e.ToString())); response.Errors = s.ToArray(); } } catch (Exception ex) { response.Errors = new string[] { ex.Message }; } response.Name = "DeleteMapResponse"; return(response); }
public AdditionalInfo SendEmail(Guid contentId, [Documentation(Name = "Subject", Type = typeof(string), Description = "Subject of the email message."), Documentation(Name = "Body", Type = typeof(string), Description = "Body of the email message."), Documentation(Name = "UserIds", Type = typeof(string), Description = "One or more comma separated user Ids."), Documentation(Name = "UserEmails", Type = typeof(string), Description = "One or more comma separated emails.")] IDictionary options) { var result = new AdditionalInfo(); var subject = string.Empty; if (options["Subject"] == null || string.IsNullOrWhiteSpace(options["Subject"].ToString())) { result.Errors.Add(new Error(typeof(FormatException).ToString(), "Email subject cannot be empty.")); } else { subject = options["Subject"].ToString(); } var body = string.Empty; if (options["Body"] == null || string.IsNullOrWhiteSpace(options["Body"].ToString())) { result.Errors.Add(new Error(typeof(FormatException).ToString(), "Email body cannot be empty.")); } else { body = options["Body"].ToString(); } if (result.HasErrors()) { return(result); } int fromUserId = Extensibility.Api.Version1.PublicApi.Users.AccessingUser.Id.Value; if (options["UserIds"] != null && !string.IsNullOrWhiteSpace(options["UserIds"].ToString())) { try { var userIds = options["UserIds"].ToString().Split(',').Select(int.Parse); foreach (var userId in userIds) { var sended = Extensibility.Api.Version1.PublicApi.SendEmail.Send( new Extensibility.Api.Version1.SendEmailOptions { Subject = subject, Body = body, FromUserId = fromUserId, ToUserId = userId, }); if (!sended) { result.Errors.Add(new Error(typeof(InvalidOperationException).ToString(), plugin.Translate(SharePointFileExtension.Translations.EmailSendError))); } } } catch (Exception ex) { result.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.EmailSendError))); } } if (options["UserEmails"] != null && !string.IsNullOrWhiteSpace(options["UserEmails"].ToString())) { try { var userEmails = options["UserEmails"].ToString().Split(','); foreach (var userEmail in userEmails) { var sended = Extensibility.Api.Version1.PublicApi.SendEmail.Send( new Extensibility.Api.Version1.SendEmailOptions { Subject = subject, Body = body, FromUserId = fromUserId, ToEmail = userEmail, }); if (!sended) { result.Errors.Add(new Error(typeof(InvalidOperationException).ToString(), plugin.Translate(SharePointFileExtension.Translations.EmailSendError))); } } } catch (Exception ex) { result.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.EmailSendError))); } } return(result); }
public AdditionalInfo Add(Guid contentId, [Documentation(Name = "FieldName", Type = typeof(string), Description = "\"Attachments\" by default"), Documentation(Name = "File", Type = typeof(string), Description = "File Name"), Documentation(Name = "Data", Type = typeof(byte[]), Description = "Byte array file content")] IDictionary options) { var result = new AdditionalInfo(); string fieldName = "Attachments"; if (options["FieldName"] != null) { fieldName = options["FieldName"].ToString(); } string fileName = null; if (options["File"] != null) { fileName = options["File"].ToString(); } if (string.IsNullOrWhiteSpace(fileName)) { result.Errors.Add(new Error(typeof(ArgumentException).ToString(), Plugin.Translate(AttachmentsExtension.Translations.FileNameCannotBeEmpty))); } var data = options["Data"] as byte[]; if (data == null) { result.Errors.Add(new Error(typeof(ArgumentException).ToString(), Plugin.Translate(AttachmentsExtension.Translations.FileContentCannotBeEmpty))); } if (!result.HasErrors()) { try { PublicApi.Attachments.Add(EnsureListId(contentId), new AttachmentsAddOptions(contentId, fieldName) { Files = new Dictionary <string, byte[]> { { fileName, data } } }); } catch (InvalidOperationException ex) { result.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(AttachmentsExtension.Translations.ListItemNotFound, contentId))); } catch (SPInternalException ex) { result.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(AttachmentsExtension.Translations.ListItemNotFound, contentId))); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.AttachmentsEditor.Add() method for ContentId: {1}. The exception message is: {2}", ex.GetType(), contentId, ex.Message); SPLog.UnKnownError(ex, message); result.Errors.Add(new Error(ex.GetType().ToString(), Plugin.Translate(AttachmentsExtension.Translations.UnknownError, contentId))); } } return(result); }