Esempio n. 1
0
        public long AddContactUsMessage(Message message)
        {
            message.MessageGroupId = MessageGroups.ContactUs;
            message.SentDate       = DateTimeOffset.UtcNow;
            message.SentFromIP     = httpContext.HttpContext.Connection.RemoteIpAddress.ToString();

            ValidationData vd = ValidateContactUsMessage(message);

            if (!vd.Valid)
            {
                es.ThrowInfoException(vd.Message, vd.Params);
            }

            addMessage2Db(message);

            if (op.Value.Emails.SendContactUsEmailConfirmaion)
            {
                mas.SendContactUsConfirmation(message);
            }

            if (op.Value.Notifications.NotifySupportContactUsReceived)
            {
                mas.NotifySupportContactUs(message.Id.Value, message);
            }

            return(message.Id.Value);
        }
Esempio n. 2
0
        public Account RegisterNewAccount(RegistrationData registrationData)
        {
            long accountId = CreateNewAccount(registrationData);

            if (accountId == -1)
            {
                es.ThrowInfoException("Login {0} is already in use", registrationData.Login);
            }
            if (accountId == -2)
            {
                es.ThrowInfoException("Email {0} is already in use", registrationData.Email);
            }

            Account result = GetFullAccountByLogin(registrationData.Login);

            if (op.Value.Emails.SendRegisterEmailConfirmaion)
            {
                mas.SendRegisterConfirmation(result);
            }

            if (op.Value.Notifications.NotifyAdminAccountRegistered)
            {
                mas.NotifyAdminAccountRegistered(result);
            }


            return(result);
        }
Esempio n. 3
0
        // TODO: reduce login and page names down to reasonable minimum, because path length is limited wih 248 (?) characters
        public async Task <string> UploadElementImage(string login, PageElement pageElement, IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                es.ThrowException("File is empty");
            }

            if (string.IsNullOrWhiteSpace(options.Value.AccountImagesPath))
            {
                es.ThrowException("No account images path in configuration");
            }

            if (string.IsNullOrWhiteSpace(login))
            {
                es.ThrowException("No login to save an image to");
            }

            Tuple <string, string> ext = imageTypes.FirstOrDefault(x => string.Equals(x.Item1, file.ContentType, StringComparison.OrdinalIgnoreCase));

            if (ext == null)
            {
                es.ThrowInfoException("File to upload is not an image");
            }

            if (file.Length > options.Value.Images.InputSizeLimit * 1024 * 1024)
            {
                es.ThrowInfoException("File to upload exceeds a limit {0} Mb",
                                      options.Value.Images.InputSizeLimit.ToString());
            }

            string relativePath = Path.Combine(options.Value.AccountImagesPath, login, pageElement.ToString());
            string path         = Path.Combine(environment.WebRootPath, relativePath);

            Directory.CreateDirectory(path);

            List <string> files =
                Directory
                .GetFiles(path)
                .Where(x => Path.GetFileNameWithoutExtension(x) == file.FileName ||
                       Path.GetFileNameWithoutExtension(x) == file.FileName + "_")
                .ToList();

            bool add_ = files.Count > 0 && !files.Any(x => Path.GetFileNameWithoutExtension(x) == file.FileName + "_");

            files.ForEach(x => File.Delete(x));

            string fileName = file.FileName + (add_ ? "_" : "") + "." + ext.Item2;

            using (var fileStream = new FileStream(Path.Combine(path, fileName), FileMode.Create))
            {
                if (file.Length > options.Value.Images.ConvertSizeLimit * 1024)
                {
                    reduceImageSize(file, fileStream);
                }
                else
                {
                    await file.CopyToAsync(fileStream);
                }
            }

            return(Path.Combine(relativePath, fileName).Replace('\\', '/'));
        }