Exemple #1
0
        private async Task ChangeEmail()
        {
            if (ValidateData())
            {
                if (await dialogService.ShowConfirm(AppResources.QuestionConfirmChangeEmail, AppResources.ConfirmChangeEmail))
                {
                    dialogService.ShowProgress();
                    RequestEmail request = new RequestEmail
                    {
                        OldEmail     = OldEmail,
                        NewEmail     = NewEmail,
                        ConfirmEmail = ConfirmEmail
                    };
                    ResponseBase response = await apiService.ChangeEmail(request);

                    dialogService.HideProgress();
                    await ValidateDataResponseChangeEmail(response);
                }
                else
                {
                    OldEmail     = string.Empty;
                    NewEmail     = string.Empty;
                    ConfirmEmail = string.Empty;
                }
                return;
            }
        }
 private static void timer_Tick(object sender, EventArgs e)
 {
     if (calculateExpiringFoodItem().Count >= 1)
     {
         RequestEmail.postEmailRequestToEmailAPI(calculateExpiringFoodItem());
     }
 }
Exemple #3
0
        public async Task <IActionResult> Create(int?id, [Bind("Id,ProductId,PackageTypeId,StoreId,StorePrice,StoreCost,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] ProductStoreSpecific productStoreSpecific)
        {
            productStoreSpecific.Id = 0;
            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                    productStoreSpecific.CreatedBy = userFullName;
                }

                productStoreSpecific.CreatedOn = DateTime.Now;

                productStoreSpecific.ProductId = id;
                _dbWriteService.Add(productStoreSpecific);
                await _dbWriteService.SaveChangesAsync();

                var request = await _dbReadService.GetSingleRecordAsync <Request>(s => s.Id.Equals(RequestDto.RequestId));

                RequestEmail requestEmail = new RequestEmail(_configuration, _dbReadService);
                requestEmail.SendNewRequestToHeadQuarters(request);

                return(RedirectToAction("Index", "ProductStoreSpecificProducts", new { id = productStoreSpecific.ProductId }));
            }

            ViewData["ProductId"] = new SelectList(_context.Product, "Id", "ProductName", productStoreSpecific.ProductId);

            return(View(productStoreSpecific));
        }
Exemple #4
0
        public async Task <IActionResult> CreateNote(int?id, [Bind("Id,NoteText,SendEmailRequestor,SendEmailSupplier,RequestId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Note note)
        {
            note.Id = 0;
            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                    note.CreatedBy = userFullName;
                }

                note.CreatedOn = DateTime.Now;
                note.RequestId = id;
                _dbWriteService.Add(note);

                await _dbWriteService.SaveChangesAsync();

                var request = await _dbReadService.GetSingleRecordAsync <Request>(r => r.Id.Equals(id));

                if (note.SendEmailSupplier == true)
                {
                    RequestEmail emailSupplier = new RequestEmail(_configuration, _dbReadService);
                    emailSupplier.SendNewNoteEmailToSuppliers(request, note);
                }

                if (note.SendEmailRequestor == true)
                {
                    RequestEmail emailOriginator = new RequestEmail(_configuration, _dbReadService);
                    var          user            = await _dbReadService.GetSingleRecordAsync <Entity.Models.User>(u => u.EmailAddress.Equals(request.UserId));

                    if (user != null)
                    {
                        if (user.SupplierId != null && user.SupplierId > 0)
                        {
                            emailOriginator.SendNewNoteEmailToOriginatingUser(request, note, user.SupplierId);
                        }
                        else
                        {
                            emailOriginator.SendNewNoteEmailToOriginatingUser(request, note);
                        }
                    }
                }
            }
            return(RedirectToAction("Index", "Notes", new { id = note.RequestId }));
        }
        public async Task <IActionResult> CreateProductAndPackage(int id, [Bind("Id,ProductName,ProductDescription,Upccode,ProductLocation,ProductCost,ProductPrice,SuggestedPrice,PackageSize,PackageType,ContainerSizeTypeId,ContainerTypeId,OrderWeek,CategoryId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy,UnitsPerCase,SupplierData")] Product product)
        {
            var requestId = RequestDto.RequestId;

            product.Id = 0;

            if (ModelState.IsValid)
            {
                if (User != null)
                {
                    var userFullName = User.Claims.FirstOrDefault(x => x.Type == $"emails").Value;
                    product.CreatedBy = userFullName;
                }

                product.CreatedOn = DateTime.Now;

                _dbWriteService.Add(product);
                await _dbWriteService.SaveChangesAsync();

                _dbReadService.IncludeEntityNavigation <Request>();
                var request = await _dbReadService.GetSingleRecordAsync <Request>(s => s.Id.Equals(requestId));

                request.ProductId = product.Id;
                _dbWriteService.Update(request);
                await _dbWriteService.SaveChangesAsync();

                if (request.StoreId != null)
                {
                    RequestEmail requestEmail = new RequestEmail(_configuration, _dbReadService);
                    requestEmail.SendRequestToStoreManager(request);
                }

                RequestLogHelper logHelper = new RequestLogHelper();
                logHelper.LogRequestChange(request, _context, RequestLogConstants.RequestAddByVendor);
            }

            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "CategoryName", product.CategoryId);
            ViewData["OrderWeeks"] = new SelectList(new Dictionary <int, int>()
            {
                { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 }, { 8, 8 }, { 9, 9 }
            }, "Key", "Value", product.OrderWeek);

            return(RedirectToAction("Create", "ProductPackageTypes", new { id = product.Id }));
        }
Exemple #6
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int UserID        = 0;
            int intCampaignID = 0; // lblCurrentCampaign.Text.ToString().ToInt32();

            int.TryParse(ddlCampaign.SelectedValue, out intCampaignID);
            if (Session["CampaignPlayerRoleID"] == null)
            {
                Session["CampaignPlayerRoleID"] = 0;
            }
            int    CampaignPlayerRoleID = Session["CampaignPlayerRoleID"].ToString().ToInt32();
            string strUsername          = "";
            string RequestEmail;

            if (Session["Username"] != null)
            {
                strUsername = "";
            }
            else
            {
                strUsername = Session["Username"].ToString();
            }
            if (Session["UserID"].ToString().ToInt32() != 0)
            {
                UserID = Session["UserID"].ToString().ToInt32();
            }
            Classes.cCampaignBase Campaign = new Classes.cCampaignBase(intCampaignID, strUsername, UserID);
            if (Campaign.JoinRequestEmail == "")
            {
                RequestEmail = Campaign.InfoRequestEmail;
            }
            else
            {
                RequestEmail = Campaign.JoinRequestEmail;
            }
            if (RequestEmail.Contains("@"))
            {
                // It has a "@".  Assume the email format is close enough, go on.
            }
            else
            {
                RequestEmail = "";
            }
            foreach (ListItem item in cblRole.Items)
            {
                if (item.Selected)
                {
                    switch (item.Value)
                    {
                    case "NPC":
                        // Permanent NPC needs approval
                        if (RequestEmail == "")
                        {
                            SignUpForSelectedRole(6, UserID, intCampaignID, 55);
                        }
                        else
                        {
                            SendApprovalEmail(intCampaignID, UserID, 6, RequestEmail);
                            SignUpForSelectedRole(10, UserID, intCampaignID, 56);
                        }
                        Response.Redirect("~/General/MemberHome.aspx");
                        break;

                    case "6False":
                        // Permanent NPC no approval
                        SignUpForSelectedRole(6, UserID, intCampaignID, 55);
                        break;

                    case "EventNPC":
                        // Event NPC needs approval
                        if (RequestEmail == "")
                        {
                            SignUpForSelectedRole(7, UserID, intCampaignID, 55);
                        }
                        else
                        {
                            SendApprovalEmail(intCampaignID, UserID, 7, RequestEmail);
                            SignUpForSelectedRole(10, UserID, intCampaignID, 56);
                        }
                        Response.Redirect("~/General/MemberHome.aspx");
                        break;

                    case "7False":
                        // Event NPC no approval
                        SignUpForSelectedRole(7, UserID, intCampaignID, 55);
                        break;

                    case "PC":
                        // PC needs approval
                        if (RequestEmail == "")
                        {
                            SignUpForSelectedRole(8, UserID, intCampaignID, 55);
                        }
                        else
                        {
                            SendApprovalEmail(intCampaignID, UserID, 8, RequestEmail);
                            SignUpForSelectedRole(8, UserID, intCampaignID, 56);
                        }
                        Response.Redirect("~/General/MemberHome.aspx");
                        break;

                    case "8False":
                        // PC no approval
                        SignUpForSelectedRole(8, UserID, intCampaignID, 55);
                        break;

                    case "10True":
                        // NPC needs approval
                        if (RequestEmail == "")
                        {
                            SignUpForSelectedRole(10, UserID, intCampaignID, 55);
                        }
                        else
                        {
                            SendApprovalEmail(intCampaignID, UserID, 10, RequestEmail);
                            SignUpForSelectedRole(10, UserID, intCampaignID, 56);
                        }
                        break;

                    case "10False":
                        // NPC no approval
                        SignUpForSelectedRole(10, UserID, intCampaignID, 55);
                        break;

                    default:
                        // Technically we shouldn't be able to get here so do nothing
                        Response.Redirect("~/General/MemberHome.aspx");
                        break;
                    }
                }
            }
            Response.Redirect("~/General/MemberHome.aspx");
        }
Exemple #7
0
 private void b_sendHtmlEmail_Click(object sender, RoutedEventArgs e)
 {
     RequestEmail.postEmailRequestToEmailAPIWithHTMLBody();
 }
Exemple #8
0
        public virtual FileInfo DownloadFile(string url, string filename)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException(nameof(url));
            }

            if (string.IsNullOrWhiteSpace(RequestEmail) || !RequestEmail.Contains('@') || RequestEmail.Length < 10)
            {
                Log.WriteLine("Internal error. Cannot request FTP content because no contact email is provided.", LogLevel.Error);
                throw new InvalidOperationException("No valid requesting contact email provided. Please set the RequestEmail to continue. Cant comply.");
            }

            FileInfo localFile = new FileInfo(Path.Combine(CacheDirectory, filename));

            if (!localFile.Directory.Exists)
            {
                localFile.Directory.Create();
            }

            if (OfflineMode)
            {
                localFile.Refresh();
                if (!localFile.Exists)
                {
                    throw new FileNotFoundException("The downloaded file cannot be located. Application is in offline mode.");
                }

                Log.WriteLine("Offline mode. No file download for %@. Cached file size: %@ bytes", LogLevel.Message, localFile.Name, localFile.Length.ToString("N0"));

                return(localFile);
            }

            if (FtpClient == null)
            {
                FtpClient = new FluentFTP.FtpClient(PublicFtpHostname, PublicFtpPort, new System.Net.NetworkCredential("anonymous", RequestEmail));
                FtpClient.ConnectTimeout = 7000;
                FtpClient.DataConnectionConnectTimeout = 7000;
                FtpClient.DataConnectionReadTimeout    = 10000;
                FtpClient.ReadTimeout = 7000;
            }
            else
            {
                Log.WriteLine("Reusing existing FTP connection to ftp://%@@%@:%@", LogLevel.Debug, FtpClient.Credentials.UserName, PublicFtpHostname, PublicFtpPort.ToString());
            }

            int  tryIndex            = 0;
            int  maxTries            = 10;
            int  tryDelayFormulaBase = 2;
            bool abortLoop           = false;

            while (!FtpClient.IsConnected)
            {
                try
                {
                    if (tryIndex >= maxTries)
                    {
                        abortLoop = true;
                        throw new IOException("Cannot connect to the remote server.");
                    }

                    int delay = tryIndex > 0 ? (int)Math.Pow(tryDelayFormulaBase, tryIndex) : 0;
                    if (delay > 0)
                    {
                        if (Settings.Current.HeadlessMode)
                        {
                            Log.Write("Retrying in %@ seconds... ", LogLevel.Message, delay.ToString("N0"));
                            System.Threading.Thread.Sleep(delay * 1000);
                        }
                        else
                        {
                            Log.Write("Retrying in %@ seconds. Press Q at any time to abort. ", LogLevel.Message, delay.ToString("N0"));
                            for (int i = 0; i < delay; i++)
                            {
                                System.Threading.Thread.Sleep(1000);
                                while (Console.KeyAvailable)
                                {
                                    if (Console.ReadKey().Key == ConsoleKey.Q)
                                    {
                                        abortLoop = true;
                                        throw new TimeoutException("The operation timed out and a retry attempt was aborted");
                                    }
                                }
                            }
                        }
                        Log.WriteLine("Retrying...");
                    }

                    if (tryIndex > 0)
                    {
                        Log.Write("Try %@ of %@. ", LogLevel.Message, tryIndex + 1, maxTries);
                    }
                    tryIndex++;

                    Log.Write("Connecting to the remote FTP host (%@) at ftp://%@@%@:%@... ", LogLevel.Message, Identifier, FtpClient.Credentials.UserName, PublicFtpHostname, PublicFtpPort.ToString());
                    FtpClient.RetryAttempts = 1;
                    FluentFTP.FtpProfile profile = FtpClient.AutoConnect();

                    if (profile == null || !FtpClient.IsConnected)
                    {
                        throw new TimeoutException("The operation timed out.");
                    }

                    Log.WriteColoredLine("OK! (%@)", ConsoleColor.Green, LogLevel.Message, profile.DataConnection.ToString());
                }
                catch (Exception ex)
                {
                    Log.WriteColoredLine("FAIL!", ConsoleColor.Red, LogLevel.Error);
                    Log.WriteLine("Failed to connect. %@. %@", LogLevel.Error, ex.GetType().Name, ex.Message);

                    if (abortLoop)
                    {
                        throw;
                    }
                }
            }

            Log.WriteLine("Connected to ftp://%@@%@:%@/. Server Type: %@", LogLevel.Debug, FtpClient.Credentials.UserName, PublicFtpHostname, PublicFtpPort.ToString(), FtpClient.SystemType);
            Log.WriteLine("Requesting file info for %@...", LogLevel.Debug, url);

            try
            {
                FluentFTP.FtpListItem remoteFileInfo = FtpClient.GetObjectInfo(url);
                if (remoteFileInfo == null)
                {
                    throw new IOException("The requested FTP file does not exists.");
                }

                FtpCurrentTransferSize = FtpClient.GetFileSize(url);
                Log.WriteLine("   File size: %@ bytes.", LogLevel.Debug, FtpCurrentTransferSize.ToString("N0"));
                if (FtpCurrentTransferSize == 0)
                {
                    //FtpClient.Disconnect();
                    throw new IOException("The requested file is empty.");
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine("An error occurred while requesting file info. %@. %@", LogLevel.Warning, ex.GetType().Name, ex.Message);
                throw;
            }

            try
            {
                using (FileStream fs = new FileStream(localFile.FullName, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    FtpClient.Download(fs, url, progress: FtpTransferProgressUpdated);

                    if (Console.CursorLeft > 0)
                    {
                        Log.WriteLine();
                    }

                    if (fs.Position == FtpCurrentTransferSize || FtpCurrentTransferSize == -1)
                    {
                        Log.WriteLine("File transfer completed. %@ bytes received.", LogLevel.Debug, fs.Position.ToString("N0"));
                    }
                    else
                    {
                        Log.WriteLine("File transfer completed but file size differs!!. Expected %@ but received %@ bytes.", LogLevel.Error, FtpCurrentTransferSize.ToString("N0"), fs.Position.ToString("N0"));

                        if (!Settings.Current.IgnoreFtpTransferSizeMismatch)
                        {
                            //FtpClient.Disconnect();
                            throw new IOException("The received file doesnt match the expected file length.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine("An error occurred while requesting the file. %@. %@. Aborted.", LogLevel.Error, ex.GetType().Name, ex.Message);
                throw;
            }

            //FtpClient.Disconnect();
            //Log.WriteLine("Disconnected from FTP server.", LogLevel.Debug);

            localFile.Refresh();
            return(localFile);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int intCampaignID = 0;

            int.TryParse(ddlCampaign.SelectedValue, out intCampaignID);
            string RequestEmail;

            int iUserID = 0;

            if (!int.TryParse(hidUserID.Value, out iUserID))
            {
                iUserID = 0;
            }

            Classes.cCampaignBase Campaign = new Classes.cCampaignBase(intCampaignID, hidUsername.Value, iUserID);
            if (Campaign.JoinRequestEmail == "")
            {
                RequestEmail = Campaign.InfoRequestEmail;
            }
            else
            {
                RequestEmail = Campaign.JoinRequestEmail;
            }
            if (RequestEmail.Contains("@"))
            {
                // It has a "@".  Assume the email format is close enough, go on.
            }
            else
            {
                RequestEmail = "";
            }
            foreach (ListItem item in cblRole.Items)
            {
                if (item.Selected)
                {
                    switch (item.Value)
                    {
                    case "NPC":
                        // Permanent NPC needs approval
                        if (RequestEmail == "")
                        {
                            SignUpForSelectedRole(6, iUserID, intCampaignID, 55);
                        }
                        else
                        {
                            SendApprovalEmail(intCampaignID, iUserID, 6, RequestEmail);
                            SignUpForSelectedRole(10, iUserID, intCampaignID, 56);
                        }
                        Response.Redirect("~/Default.aspx");
                        break;

                    case "6False":
                        // Permanent NPC no approval
                        SignUpForSelectedRole(6, iUserID, intCampaignID, 55);
                        break;

                    case "EventNPC":
                        // Event NPC needs approval
                        if (RequestEmail == "")
                        {
                            SignUpForSelectedRole(7, iUserID, intCampaignID, 55);
                        }
                        else
                        {
                            SendApprovalEmail(intCampaignID, iUserID, 7, RequestEmail);
                            SignUpForSelectedRole(10, iUserID, intCampaignID, 56);
                        }
                        Response.Redirect("~/Default.aspx");
                        break;

                    case "7False":
                        // Event NPC no approval
                        SignUpForSelectedRole(7, iUserID, intCampaignID, 55);
                        break;

                    case "PC":
                        // PC needs approval
                        if (RequestEmail == "")
                        {
                            SignUpForSelectedRole(8, iUserID, intCampaignID, 55);
                        }
                        else
                        {
                            SendApprovalEmail(intCampaignID, iUserID, 8, RequestEmail);
                            SignUpForSelectedRole(8, iUserID, intCampaignID, 56);
                        }
                        Response.Redirect("~/Default.aspx");
                        break;

                    case "8False":
                        // PC no approval
                        SignUpForSelectedRole(8, iUserID, intCampaignID, 55);
                        break;

                    case "10True":
                        // NPC needs approval
                        if (RequestEmail == "")
                        {
                            SignUpForSelectedRole(10, iUserID, intCampaignID, 55);
                        }
                        else
                        {
                            SendApprovalEmail(intCampaignID, iUserID, 10, RequestEmail);
                            SignUpForSelectedRole(10, iUserID, intCampaignID, 56);
                        }
                        break;

                    case "10False":
                        // NPC no approval
                        SignUpForSelectedRole(10, iUserID, intCampaignID, 55);
                        break;

                    default:
                        // Technically we shouldn't be able to get here so do nothing
                        Response.Redirect("~/Default.aspx");
                        break;
                    }
                }
            }
            Response.Redirect("~/Default.aspx");
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,RequestDescription,RequestTypeId,StatusTypeId,UserId,ProductId,SupplierId,StoreId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] Request request)
        {
            if (id != request.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (User != null)
                    {
                        string claimTypeEmailAddress = $"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name";
                        var    userFullName          = User.Claims.FirstOrDefault(x => x.Type == $"name").Value;
                        request.UserId    = User.Claims.FirstOrDefault(x => x.Type == claimTypeEmailAddress).Value;
                        request.UpdatedBy = userFullName;
                    }

                    request.UpdatedOn = DateTime.Now;

                    request.ProductId = _dbReadService.GetSingleRecordAsync <Request>(p => p.Id.Equals(request.Id)).Result.ProductId;

                    _dbWriteService.Update(request);
                    await _dbWriteService.SaveChangesAsync();

                    var status = await _dbReadService.GetSingleRecordAsync <StatusType>(s => s.Id.Equals(request.StatusTypeId));

                    if (request.StatusTypeId != RequestDto.StatusId)
                    {
                        switch (status.StatusTypeName)
                        {
                        case "New Request":
                            break;

                        case "Approved":
                            RequestLogHelper logHelperApproved = new RequestLogHelper();
                            logHelperApproved.LogRequestChange(request, _context, RequestLogConstants.RequestApproved);

                            RequestEmail requestEmailManager = new RequestEmail(_configuration, _dbReadService);
                            requestEmailManager.SendApprovedRequestEmailToHeadQuarters(request);
                            break;

                        case "Denied":
                            RequestLogHelper logHelperDenied = new RequestLogHelper();
                            logHelperDenied.LogRequestChange(request, _context, RequestLogConstants.RequestDenied);

                            RequestEmail requestEmailOriginator = new RequestEmail(_configuration, _dbReadService);
                            requestEmailOriginator.SendDeniedRequestEmailToOriginatingUser(request);

                            break;

                        case "Complete":
                            RequestLogHelper logHelperComplete = new RequestLogHelper();
                            logHelperComplete.LogRequestChange(request, _context, RequestLogConstants.RequestComplete);

                            RequestEmail requestEmailCompletedStatus = new RequestEmail(_configuration, _dbReadService);
                            requestEmailCompletedStatus.SendRequestCompletedToGroup(request);
                            break;
                        }
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    bool result = await RequestExists(request.Id);

                    if (!result)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            RequestDto.StatusId = null;
            return(View(request));
        }