Beispiel #1
0
 public string Delete(string userId, string id)
 {
     Global.Response response = new Global.Response();
     if (string.IsNullOrWhiteSpace(userId))
     {
         response.isSuccess = false;
         response.msg       = "select item";
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
     if (string.IsNullOrWhiteSpace(userId))
     {
         response.isSuccess = false;
         response.msg       = "error";
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
     try {
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DB.GetDataBasePath(userId, userDataBase))) {
             connection.Open();
             string sql = string.Format("DELETE FROM favoritefoods WHERE id = '{0}'", id);
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 command.ExecuteNonQuery();
             }
             response.isSuccess = true;
         }
         return(JsonConvert.SerializeObject(response, Formatting.None));
     } catch (Exception e) {
         response.isSuccess = false;
         response.msg       = e.Message;
         L.SendErrorLog(e, id, userId, "FavoriteFoods", "Delete");
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
 }
Beispiel #2
0
 public string Delete(string userId, string[] ids, string tbl)
 {
     Global.Response response = new Global.Response();
     if (ids.Length == 0)
     {
         response.isSuccess = false;
         response.msg       = "select items";
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
     if (string.IsNullOrWhiteSpace(userId))
     {
         response.isSuccess = false;
         response.msg       = "error";
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
     try {
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DB.GetDataBasePath(userId, dataBase))) {
             connection.Open();
             foreach (var clientId in ids)
             {
                 response = DeleteRecord(userId, clientId, connection, tbl);
             }
         }
         return(JsonConvert.SerializeObject(response, Formatting.None));
     } catch (Exception e) {
         response.isSuccess = false;
         response.msg       = e.Message;
         L.SendErrorLog(e, tbl, userId, "Archives", "Delete");
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
 }
Beispiel #3
0
 public string DeleteErrorLog(string[] ids)
 {
     Global.Response response = new Global.Response();
     if (ids.Length == 0)
     {
         response.isSuccess = false;
         response.msg       = "select items";
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
     try {
         string sql = null;
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath("~/App_Data/" + usersDataBase))) {
             connection.Open();
             foreach (var id in ids)
             {
                 sql = string.Format(@"DELETE FROM errorlog WHERE errorLogId = '{0}'", id);
                 using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                     command.ExecuteNonQuery();
                 }
             }
         }
         response.isSuccess = true;
         response.msg       = "deleted";
         return(JsonConvert.SerializeObject(response, Formatting.None));
     } catch (Exception e) {
         response.isSuccess = false;
         response.msg       = e.Message;
         SendErrorLog(e, ids.ToString(), null, "Log", "DeleteErrorLog");
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
 }
Beispiel #4
0
 public Global.Response SendTicketMessage(string sendTo, string messageSubject, string messageBody, string lang, string filePath, bool send_cc)
 {
     Global.Response resp = new Global.Response();
     resp.isSuccess = SendMail(sendTo, messageSubject, messageBody, lang, filePath, send_cc).isSuccess;
     resp.msg       = true ? t.Tran("successfully sent", lang) : string.Format("{0}! {1}.", t.Tran("not sent", lang), t.Tran("please try again", lang));
     return(resp);
 }
Beispiel #5
0
        public JsonResult OnGetLoadAnalyzerInstance()
        {
            Global.Response response = new Global.Response();

            try
            {
                string userIPAddress = Global.GetUserIPAddress();

                List <CurrentAnalyzerInstancesTVF> currentAnalyzerInstancesTVFResults = _fortuneStreetAppContext.CurrentAnalyzerInstancesTVF.FromSqlInterpolated($"SELECT * FROM currentanalyzerinstances_tvf() WHERE status = 'in_progress'").OrderByDescending(timestampadded => timestampadded.TimestampAdded).ToList();

                foreach (CurrentAnalyzerInstancesTVF currentAnalyzerInstancesTVFResult in currentAnalyzerInstancesTVFResults)
                {
                    if (!Global.HashComparison(userIPAddress, currentAnalyzerInstancesTVFResult.IPAddress))
                    {
                        currentAnalyzerInstancesTVFResults.Remove(currentAnalyzerInstancesTVFResult);
                    }
                }

                response.HTMLResponse =
                    "<div>" +

                    (
                        currentAnalyzerInstancesTVFResults.Count > 0
                            ?
                        "<div class=\"horizontal-items\">" +
                        "<div>" +
                        "<select class=\"form-select\">" +

                        string.Join("", currentAnalyzerInstancesTVFResults.Select(results => "<option value=\"" + results.AnalyzerInstanceID + "\">" + results.TimestampAdded.ToLocalTime().ToString("MMMM d, yyyy h:mm:ss tt") + "</option>")) +

                        "</select>" +
                        "</div>" +

                        "<div>" +
                        "<button type=\"button\" class=\"btn btn-primary\" name=\"load\">Load</button>" +
                        "</div>" +
                        "</div>"
                            :
                        "<div>No previous analyzer instances found. Start a new one by clicking the \"Create\" button below.</div>"
                    ) +

                    "<div>" +

                    Global.CreateConfirmationActions("center-items", new List <string>
                {
                    "<button type=\"button\" class=\"btn btn-lg btn-primary\" name=\"create\">Create</button>"
                }) +

                    "</div>" +
                    "</div>";

                return(new JsonResult(response));
            }
            catch (Exception e)
            {
                return(Global.ServerErrorResponse(e));
            }
        }
Beispiel #6
0
    private Global.Response DeleteRecord(string userId, string id, SQLiteConnection connection, string tbl)
    {
        Global.Response response = new Global.Response();
        try {
            string sql = null;
            switch (tbl)
            {
            case "clients":
                sql = string.Format(@"DELETE FROM clients WHERE clientId = '{0}';
                        DELETE FROM clientsdata WHERE clientId = '{0}'", id);
                F.DeleteClientFolder(userId, id);
                break;

            case "menus":
                sql = string.Format("DELETE FROM menues WHERE id = '{0}'", id);
                F.DeleteJsonFile(userId, id, "menues", null);
                break;

            case "weeklymenus":
                sql = string.Format("DELETE FROM weeklymenus WHERE id = '{0}'", id);
                break;

            case "recipes":
                sql = string.Format("DELETE FROM recipes WHERE id = '{0}'", id);
                F.DeleteJsonFile(userId, id, "recipes", null);
                /******* Delete from My Foods if exists (Recipes as My Food) *******/
                MyFoods mf = new MyFoods();
                mf.Delete(userId, id);
                F.DeleteRecipeFolder(userId, id);
                /******* Delete from My Sharing Recipes if exists *******/
                SharingRecipes SR = new SharingRecipes();
                SR.DeleteSharedRecipe(id);
                break;

            case "foods":
                sql = string.Format("DELETE FROM myfoods WHERE id = '{0}'", id);
                break;

            case "appointments":
                sql = string.Format("DELETE FROM scheduler WHERE rowid = '{0}'", id);
                break;

            default:
                break;
            }
            using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                command.ExecuteNonQuery();
            }
            response.isSuccess = true;
            response.msg       = "deleted";
            return(response);
        } catch (Exception e) {
            response.isSuccess = false;
            response.msg       = e.Message;
            L.SendErrorLog(e, id, userId, "Archives", "DeleteRecord");
            return(response);
        }
    }
Beispiel #7
0
    public string Delete(string userGroupId, string id, string userId, int adminType, string authorId)
    {
        var x = new Global.Response();

        try {
            if (string.IsNullOrEmpty(userGroupId) || string.IsNullOrEmpty(id))
            {
                x.isSuccess = false;
                x.msg       = "tryAgainMsg";
                return(JsonConvert.SerializeObject(x, Formatting.None));
            }
            Global G = new Global();
            if (!G.CheckUserPermission(userGroupId, userId, adminType, authorId))
            {
                x.isSuccess = false;
                x.msg       = "deleteRecipePermissionAlert";
                return(JsonConvert.SerializeObject(x, Formatting.None));
            }
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userGroupId, dataBase))) {
                connection.Open();
                string sql = @"BEGIN;
                               DELETE FROM recipes WHERE id = @Id;
                               COMMIT;";
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    command.Parameters.Add(new SQLiteParameter("Id", id));
                    command.ExecuteNonQuery();
                }
            }
            Files F = new Files();
            F.DeleteJsonFile(userGroupId, id, "recipes", null);
            /******* Delete from My Foods if exists (Recipes as My Food) *******/
            MyFoods mf = new MyFoods();
            mf.Delete(userGroupId, id);
            /*******************************************************************/
            F.DeleteRecipeFolder(userGroupId, id);
            /******* Delete from My Sharing Recipes if exists *******/
            SharingRecipes SR = new SharingRecipes();
            SR.DeleteSharedRecipe(id);
            /*******************************************************************/
            x.isSuccess = true;
            x.msg       = "deleted";
            return(JsonConvert.SerializeObject(x, Formatting.None));
        } catch (Exception e) {
            x.isSuccess = false;
            x.msg       = e.Message;
            L.SendErrorLog(e, id, null, "Recipes", "Delete");
            return(JsonConvert.SerializeObject(x, Formatting.None));
        }
    }
Beispiel #8
0
    public string Save(NewTicket x, bool sendMail, bool attachFile, string lang)
    {
        try {
            //string path = Server.MapPath(string.Format("~/App_Data/{0}", dataBase));
            //db.CreateGlobalDataBase(path, db.tickets);
            if (string.IsNullOrWhiteSpace(x.id))
            {
                x.id = Convert.ToString(Guid.NewGuid());
            }
            Global G = new Global();
            x.title = G.RemoveSingleQuotes(x.title);
            x.desc  = G.RemoveSingleQuotes(x.desc);
            x.note  = G.RemoveSingleQuotes(x.note);
            string sql = string.Format(@"BEGIN;
                    INSERT OR REPLACE INTO tickets ({0})
                    VALUES ('{1}', '{2}', '{3}', '{4}', '{5}', '{6}', {7}, {8}, '{9}');
                    COMMIT;", mainSql, x.id, x.user.userId, x.title, x.desc, x.reportDate, x.filePath, x.status, x.priority, x.note);
            using (SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0}", Server.MapPath(dataSource)))) {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    command.ExecuteNonQuery();
                }
            }

            Users U = new Users();
            x.user = U.GetUserInfo(x.user.userId);

            if (sendMail)
            {
                Mail            M        = new Mail();
                string          myEmail  = ConfigurationManager.AppSettings["myEmail"];
                Global.Response mailResp = M.SendTicketMessage(myEmail, messageSubject: string.Format("TICKET - {0}", x.user.email), messageBody: x.desc, lang: lang, filePath: attachFile ? x.filePath : null, send_cc: true);
                x.response = mailResp;
            }
            else
            {
                x.response.isSuccess = true;
                x.response.msg       = "successfully sent";
            }

            return(JsonConvert.SerializeObject(x, Formatting.None));
        } catch (Exception e) {
            x.response.isSuccess = false;
            x.response.msg       = e.Message;
            L.SendErrorLog(e, x.id, x.user.userId, "Tickets", "Save");
            return(JsonConvert.SerializeObject(x, Formatting.None));
        }
    }
Beispiel #9
0
    public string Delete(string id)
    {
        var resp = new Global.Response();

        try {
            DeleteSharedRecipe(id);
            resp.isSuccess = true;
            resp.msg       = "saved";
            return(JsonConvert.SerializeObject(resp, Formatting.None));
        } catch (Exception e) {
            resp.isSuccess = false;
            resp.msg       = e.Message;
            L.SendErrorLog(e, id, null, "SharingRecipes", "Delete");
            return(JsonConvert.SerializeObject(resp, Formatting.None));
        }
    }
Beispiel #10
0
        public JsonResult OnPostSaveAnalyzerData([FromBody] SaveAnalyzerDataModel saveAnalyzerParameter)
        {
            Global.Response response = new Global.Response();

            try
            {
                long?analyzerInstanceID = Global.VerifyAnalyzerInstanceID(saveAnalyzerParameter.analyzerData.AnalyzerInstanceID, _fortuneStreetAppContext);

                if (analyzerInstanceID == null)
                {
                    throw new Exception();
                }

                List <PropertyInfo> analyzerDataModelProperties = typeof(Global.AnalyzerDataModel).GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList();

                foreach (PropertyInfo currentAnalyzerDataModelProperty in analyzerDataModelProperties)
                {
                    if (saveAnalyzerParameter.keys.Contains(currentAnalyzerDataModelProperty.Name))
                    {
                        _fortuneStreetAppContext.AnalyzerInstanceLogs.Add(new AnalyzerInstanceLogs
                        {
                            AnalyzerInstanceID = (long)analyzerInstanceID,
                            Key   = currentAnalyzerDataModelProperty.Name,
                            Value = JsonSerializer.Serialize(currentAnalyzerDataModelProperty.GetValue(saveAnalyzerParameter.analyzerData, null))
                        });
                    }
                }

                _fortuneStreetAppContext.SaveChanges();

                response.AlertData = new Global.Response.Alert
                {
                    Type  = "alert-success",
                    Title = "Saved data..."
                };
            }
            catch
            {
                response.AlertData = new Global.Response.Alert
                {
                    Type  = "alert-warning",
                    Title = "Cannot save data..."
                };
            }

            return(new JsonResult(response));
        }
Beispiel #11
0
 public string CreateGlobalDataBase(string dataBase)
 {
     Global.Response response = new Global.Response();
     try {
         DataBase DB     = new DataBase();
         string[] tables = { };
         if (dataBase == ConfigurationManager.AppSettings["UsersDataBase"])
         {
             tables = new [] { DB.users, DB.loginlog, DB.errorlog };
         }
         else if (dataBase == ConfigurationManager.AppSettings["WebDataBase"])
         {
             tables = new[] { DB.orders, DB.instals, DB.invoices, DB.tickets };
         }
         else if (dataBase == ConfigurationManager.AppSettings["SharingDataBase"])
         {
             tables = new[] { DB.sharingrecipes };
         }
         else
         {
             response.isSuccess = false;
             response.msg       = "select items";
             return(JsonConvert.SerializeObject(response, Formatting.None));
         }
         string path = HttpContext.Current.Server.MapPath(string.Format("~/App_Data/{0}", dataBase));
         if (tables.Length == 0)
         {
             response.isSuccess = false;
             response.msg       = "select items";
             return(JsonConvert.SerializeObject(response, Formatting.None));
         }
         foreach (var table in tables)
         {
             DB.CreateGlobalDataBase(path, table);
         }
         response.isSuccess = true;
         response.msg       = "ok";
         return(JsonConvert.SerializeObject(response, Formatting.None));
     } catch (Exception e) {
         response.isSuccess = false;
         response.msg       = e.Message;
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
 }
Beispiel #12
0
    public string Delete(Users.NewUser user, NewMenu menu)
    {
        var x = new Global.Response();

        try {
            if (!string.IsNullOrEmpty(user.userGroupId) && !string.IsNullOrEmpty(menu.id))
            {
                Global G = new Global();
                if (!G.CheckUserPermission(user, menu.userId))
                {
                    x.isSuccess = false;
                    x.msg       = "you can only delete menus that you have created yourself";
                    return(JsonConvert.SerializeObject(x, Formatting.None));
                }
                using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(user.userGroupId, userDataBase))) {
                    connection.Open();
                    string sql = string.Format("DELETE FROM menues WHERE id = '{0}'", menu.id);
                    using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                        command.ExecuteNonQuery();
                    }
                    F.DeleteJsonFile(user.userGroupId, menu.id, "menues", null);
                }
                x.isSuccess = true;
                x.msg       = "deleted";
                return(JsonConvert.SerializeObject(x, Formatting.None));
            }
            else
            {
                x.isSuccess = false;
                x.msg       = "error";
                return(JsonConvert.SerializeObject(x, Formatting.None));
            }
        } catch (Exception e) {
            x.isSuccess = false;
            x.msg       = e.Message;
            L.SendErrorLog(e, menu.id, user.userId, "Menues", "Delete");
            return(JsonConvert.SerializeObject(x, Formatting.None));
        }
    }
Beispiel #13
0
    public string Save(string userId, string id)
    {
        Global.Response response = new Global.Response();
        if (string.IsNullOrWhiteSpace(id))
        {
            response.isSuccess = false;
            response.msg       = "select item";
            return(JsonConvert.SerializeObject(response, Formatting.None));
        }
        if (string.IsNullOrWhiteSpace(userId))
        {
            response.isSuccess = false;
            response.msg       = "error";
            return(JsonConvert.SerializeObject(response, Formatting.None));
        }
        try {
            //DB.CreateDataBase(userId, DB.favoriteFoods);
            string sql = null;
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + DB.GetDataBasePath(userId, userDataBase))) {
                connection.Open();
                sql = string.Format(@"INSERT OR REPLACE INTO favoritefoods VALUES ('{0}')", id);
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    using (SQLiteTransaction transaction = connection.BeginTransaction()) {
                        command.ExecuteNonQuery();
                        transaction.Commit();
                    }
                }
            }

            response.isSuccess = true;
            return(JsonConvert.SerializeObject(response, Formatting.None));
        } catch (Exception e) {
            response.isSuccess = false;
            response.msg       = e.Message;
            L.SendErrorLog(e, id, userId, "FavoriteFoods", "Save");
            return(JsonConvert.SerializeObject(response, Formatting.None));
        }
    }
Beispiel #14
0
 public string Delete(string userId, string clientId)
 {
     Global.Response response = new Global.Response();
     try {
         using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(userId, dataBase))) {
             connection.Open();
             string sql = @"DELETE FROM clients WHERE clientId = @ClientId;
                     DELETE FROM clientsdata WHERE clientId = @ClientId";
             using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                 command.Parameters.Add(new SQLiteParameter("ClientId", clientId));
                 command.ExecuteNonQuery();
             }
             F.DeleteClientFolder(userId, clientId);
         }
         response.isSuccess = true;
         response.msg       = "deleted";
         return(JsonConvert.SerializeObject(response, Formatting.None));
     } catch (Exception e) {
         response.isSuccess = false;
         response.msg       = e.Message;
         L.SendErrorLog(e, clientId, userId, "Clients", "Delete");
         return(JsonConvert.SerializeObject(response, Formatting.None));
     }
 }
Beispiel #15
0
        public JsonResult OnGetLoadGameSelection()
        {
            Global.Response response = new Global.Response();

            try
            {
                List <Rules> rules = _fortuneStreetAppContext.Rules.OrderBy(name => name.Name).ToList();

                List <Boards> boards = _fortuneStreetAppContext.Boards.OrderBy(name => name.Name).ToList();

                List <Colors> miiColors = _fortuneStreetAppContext.Colors.OrderBy(id => id.ID).ToList();

                response.HTMLResponse = JsonSerializer.Serialize(new
                {
                    Data = new Global.AnalyzerDataModel
                    {
                        GameSelection = new Global.AnalyzerDataModel.GameSelectionDataModel
                        {
                            RuleID  = rules.FirstOrDefault().ID,
                            BoardID = boards.FirstOrDefault().ID,
                            ColorID = miiColors.FirstOrDefault().ID
                        }
                    },
                    Response =
                        "<div id=\"settings-content\">" +
                        "<div id=\"game-selection\">" +
                        "<div>" +
                        "<div>" +
                        "<h5>Rules</h5>" +
                        "</div>" +

                        "<div>" +
                        "<select class=\"form-select\">" +

                        string.Join("", rules.Select(rule => "<option value=\"" + rule.ID + "\">" + rule.Name + "</option>")) +

                        "</select>" +
                        "</div>" +
                        "</div>" +

                        "<div>" +
                        "<div>" +
                        "<h5>Boards</h5>" +
                        "</div>" +

                        "<div>" +
                        "<select class=\"form-select\">" +

                        string.Join("", boards.Select(board => "<option value=\"" + board.ID + "\">" + board.Name + "</option>")) +

                        "</select>" +
                        "</div>" +
                        "</div>" +

                        "<div>" +
                        "<div>" +
                        "<h5>Mii Color</h5>" +
                        "</div>" +

                        "<div class=\"color-selection center-items\">" +

                        string.Join("", miiColors.Select
                                    (
                                        (color, index) =>
                                        "<div>" +
                                        "<input type=\"hidden\" data-colorid=\"" + color.ID + "\" />" +

                                        "<div style=\"background-color: #" + color.MiiColor + "\"" + (index == 0 ? " class=\"selected\"" : "") + "></div>" +
                                        "</div>"
                                    )) +

                        "</div>" +
                        "</div>" +

                        Global.CreateConfirmationActions("center-items", new List <string>
                    {
                        "<button type=\"button\" class=\"btn btn-lg btn-primary\" name=\"confirm\">Confirm</button>"
                    }) +

                        "</div>" +
                        "</div>"
                });

                return(new JsonResult(response));
            }
            catch (Exception e)
            {
                return(Global.ServerErrorResponse(e));
            }
        }
Beispiel #16
0
    public Global.Response SendMail(string sendTo, string subject, string body, string lang, string file, bool send_cc)
    {
        Global.Response resp = new Global.Response();
        if (!isSendMail || (!sendTo.Contains("@") && !sendTo.Contains(".")))
        {
            resp.isSuccess = true;
            return(resp);
        }
        try {
            string footer = "";
            if (lang == "en")
            {
                myServerHost = myServerHost_en;
                myServerPort = myServerPort_en;
                myEmail      = myEmail_en;
                myEmailName  = myEmailName_en;
                myPassword   = myPassword_en;
                footer       = @"
<br>
<br>
<br>
<div><img alt=""nutriprog.com"" height=""40"" src=""https://www.nutriprog.com/assets/img/logo.svg"" style=""float:left"" width=""190"" /></div>
<br>
<br>
<br>
<div>IG PROG</div>
<div><a href=""mailto:[email protected]?subject=Upit"">[email protected]</a></div>
<div><a href = ""https://www.nutriprog.com"">www.nutriprog.com</a></div>";
            }
            else
            {
                footer = @"
<br>
<br>
<br>
<div>
    <img alt=""ProgramPrehrane.com"" height=""40"" src=""https://www.programprehrane.com/assets/img/logo.svg"" style=""float:left"" width=""190"" />
</div>
<br>
<br>
<br>
<div style=""color:gray"">
    IG PROG - obrt za računalno programiranje<br>
    Ludvetov breg 5, 51000 Rijeka, HR<br>
    <a href=""tel:+385 98 330 966"">+385 98 330 966</a><br>
    <a href=""mailto:[email protected]?subject=Upit"">[email protected]</a><br>
    <a href=""https://www.programprehrane.com"">www.programprehrane.com</a>
</div>";
            }

            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(myEmail, myEmailName);
            mail.To.Add(sendTo);
            if (send_cc && sendTo != myEmail_cc)
            {
                mail.CC.Add(myEmail_cc);
            }
            mail.Subject    = subject;
            mail.Body       = string.Format(@"
{0}

{1}", body, footer);
            mail.IsBodyHtml = true;
            if (!string.IsNullOrEmpty(file))
            {
                if (file.Contains("?"))
                {
                    file = file.Remove(file.IndexOf("?"));
                }
                Attachment attachment = new Attachment(Server.MapPath(file.Replace("../", "~/")));
                mail.Attachments.Add(attachment);
            }
            SmtpClient        smtp        = new SmtpClient(myServerHost, myServerPort);
            NetworkCredential Credentials = new NetworkCredential(myEmail, myPassword);
            smtp.Credentials = Credentials;
            smtp.EnableSsl   = EnableSsl;
            smtp.Send(mail);
            resp.isSuccess = true;
            return(resp);
        } catch (Exception e) {
            resp.isSuccess = false;
            resp.msg       = e.Message;
            L.SendErrorLog(e, subject, sendTo, "Mail", "SendMail");
            return(resp);
        }
    }
Beispiel #17
0
    public string SendOrder(NewOrder x, string lang)
    {
        Global.Response resp = new Global.Response();
        try {
            Invoice.NewInvoice i = new Invoice.NewInvoice();
            i.dateAndTime = DateTime.Now.ToString("dd.MM.yyyy, HH:mm");
            i.year        = DateTime.Now.Year;
            i.orderNumber = I.GetNextOrderNumber();
            x.orderNumber = i.orderNumber;
            i.firstName   = x.firstName;
            i.lastName    = x.lastName;
            i.companyName = x.companyName;
            i.address     = x.address;
            i.postalCode  = x.postalCode;
            i.city        = x.city;
            i.country     = x.country;
            i.pin         = x.pin;
            i.note        = x.note;
            i.items       = new List <Invoice.Item>();
            Invoice.Item item = new Invoice.Item();
            item.title = string.Format(@"{0} - {1} {2} {3}"
                                       , x.application
                                       , x.version
                                       , x.maxNumberOfUsers > 5 ? string.Format("({0} korisnika)", x.maxNumberOfUsers) : ""
                                       , string.Format("- {0} god. licenca", x.licence));
            item.qty       = Convert.ToInt32(x.licenceNumber);
            item.unitPrice = x.price;
            i.items.Add(item);

            if (x.discountCoeff > 0)
            {
                item           = new Invoice.Item();
                item.title     = string.Format(@"Popust -{0}%", Math.Round(x.discountCoeff * 100, 0));
                item.qty       = 1;
                item.unitPrice = -Math.Round(x.price - x.priceWithDiscount, 2);
                i.items.Add(item);
            }

            i.total = x.discountCoeff > 0 ? x.priceWithDiscount * item.qty : x.price * item.qty;

            i.showSignature = true;
            i.isForeign     = x.isForeign;
            i.docType       = (int)Invoice.DocType.offer;
            if (x.maxNumberOfUsers > 5)
            {
                x.note = string.Format("{0}Pod-licence: {1}"
                                       , !string.IsNullOrWhiteSpace(x.note) ? string.Format("{0};", x.note) : ""
                                       , x.maxNumberOfUsers);
            }
            if (x.eInvoice)
            {
                x.note = string.Format("{0}e-Račun"
                                       , !string.IsNullOrWhiteSpace(x.note) ? string.Format("{0};", x.note) : "");
            }


            if (string.IsNullOrEmpty(x.id))
            {
                x.id = Guid.NewGuid().ToString();
            }
            string path = HttpContext.Current.Server.MapPath("~/App_Data/" + dataBase);
            //db.CreateGlobalDataBase(path, db.orders);
            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath("~/App_Data/" + dataBase))) {
                connection.Open();
                string sql = @"INSERT INTO orders VALUES  
                       (@id, @orderNumber, @firstName, @lastName, @companyName, @address, @postalCode, @city, @country, @pin, @email, @ipAddress, @application, @version, @licence, @licenceNumber, @price, @priceEur, @orderDate, @additionalService, @note, @userGroupId, @discountCoeff)";
                using (SQLiteCommand command = new SQLiteCommand(sql, connection)) {
                    command.Parameters.Add(new SQLiteParameter("id", x.id));
                    command.Parameters.Add(new SQLiteParameter("orderNumber", x.orderNumber));
                    command.Parameters.Add(new SQLiteParameter("firstName", x.firstName));
                    command.Parameters.Add(new SQLiteParameter("lastName", x.lastName));
                    command.Parameters.Add(new SQLiteParameter("companyName", x.companyName));
                    command.Parameters.Add(new SQLiteParameter("address", x.address));
                    command.Parameters.Add(new SQLiteParameter("postalCode", x.postalCode));
                    command.Parameters.Add(new SQLiteParameter("city", x.city));
                    command.Parameters.Add(new SQLiteParameter("country", x.country));
                    command.Parameters.Add(new SQLiteParameter("pin", x.pin));
                    command.Parameters.Add(new SQLiteParameter("email", x.email));
                    command.Parameters.Add(new SQLiteParameter("ipAddress", x.ipAddress));
                    command.Parameters.Add(new SQLiteParameter("application", x.application));
                    command.Parameters.Add(new SQLiteParameter("version", x.version));
                    command.Parameters.Add(new SQLiteParameter("licence", x.licence));
                    command.Parameters.Add(new SQLiteParameter("licenceNumber", x.licenceNumber));
                    command.Parameters.Add(new SQLiteParameter("price", x.price));
                    command.Parameters.Add(new SQLiteParameter("priceEur", x.priceEur));
                    command.Parameters.Add(new SQLiteParameter("orderDate", Convert.ToString(x.orderDate)));
                    command.Parameters.Add(new SQLiteParameter("additionalService", x.additionalService));
                    command.Parameters.Add(new SQLiteParameter("note", x.note));
                    command.Parameters.Add(new SQLiteParameter("userGroupId", x.userGroupId));
                    command.Parameters.Add(new SQLiteParameter("discountCoeff", x.discountCoeff));
                    command.ExecuteNonQuery();
                }
            }

            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + Server.MapPath("~/App_Data/" + usersDataBase))) {
                connection.Open();
                string sql1 = string.Format(@"UPDATE Users SET  
                            CompanyName='{0}', Address='{1}', PostalCode='{2}', City='{3}', Country='{4}', Pin='{5}'
                            WHERE email='{6}'", x.companyName, x.address, x.postalCode, x.city, x.country, x.pin, x.email);
                using (SQLiteCommand command = new SQLiteCommand(sql1, connection)) {
                    command.ExecuteNonQuery();
                }
            }

            PrintPdf PDF = new PrintPdf();
            i.docType = (int)Invoice.DocType.offer;
            // i.totPrice_eur = x.priceEur;
            i.totPrice_eur = x.discountCoeff > 0 ? x.priceWithDiscountEur : x.priceEur;
            string offerPdf     = PDF.CreateInvoicePdf(i);
            string offerPdfPath = !string.IsNullOrEmpty(offerPdf) ? string.Format("~/upload/invoice/temp/{0}.pdf", offerPdf) : null;
            Mail   m            = new Mail();
            resp = m.SendOrder(x, lang, offerPdfPath);
            return(JsonConvert.SerializeObject(resp, Formatting.None));
        } catch (Exception e) {
            resp.isSuccess = false;
            resp.msg       = e.Message;
            L.SendErrorLog(e, x.id, x.email, "Orders", "SendOrder");
            return(JsonConvert.SerializeObject(resp, Formatting.None));
        }
    }
Beispiel #18
0
    public Global.Response SendOrder(Orders.NewOrder order, string lang, string file)
    {
        Global.Response resp = new Global.Response();
        try {
            //*****************Send mail to me****************
            string messageSubject = "Nova narudžba";
            string messageBody    = string.Format(
                @"
<h3>Nova Narudžba:</h3>
<p>Ime i prezime: {0} {1},</p>
<p>Tvrtka: {2}</p>
<p>Ulica i broj: {3}</p>
<p>Poštanski broj: {4}</p>
<p>Grad: {5}</p>
<p>Država: {6}</p>
<p>OIB: {7}</p>
<p>Email: {8}</p>
<p>Verzija: {9} {10}</p>
<p>Licenca: {11} ({12})</p>
<p>Korisnici: {13}</p>
<p>Cijena: {14} kn</p>
<p>Broj ponude: {15}/{16}</p>
<p>e-Račun: {17}</p>
"
                , order.firstName
                , order.lastName
                , order.companyName
                , order.address
                , order.postalCode
                , order.city
                , order.country
                , order.pin
                , order.email
                , order.application
                , order.version
                , order.licenceNumber
                , GetLicenceDuration(order.licence)
                , order.version.ToLower() == "premium" ? order.maxNumberOfUsers.ToString() : null
                , order.price
                , order.orderNumber
                , DateTime.UtcNow.Year
                , order.eInvoice ? "DA" : "NE");
            resp = SendMail(myEmail, messageSubject, messageBody, lang, null, true);
            //*****************Send mail to me****************

            //************ Send mail to customer****************
            messageSubject = string.Format("{0} - {1}", order.application, t.Tran("offer", lang)); // (order.application == "Program Prehrane 5.0" ? order.application : t.Tran("nutrition program web", lang)) + " - " + t.Tran("payment details", lang);
            messageBody    = PaymentDetails(order, lang);
            resp           = SendMail(order.email, messageSubject, messageBody, lang, file, false);
            //************ Send mail to customer****************
            //if (sentToMe == false || sentToCustomer == false) {
            //    resp.isSuccess = false;
            //} else {
            //    resp.isSuccess = true;
            //}
            if (resp.isSuccess)
            {
                resp.msg = t.Tran("the order have been sent successfully", lang);
            }

            return(resp);
        } catch (Exception e) {
            resp.isSuccess = false;
            resp.msg       = e.Message;
            L.SendErrorLog(e, order.id, order.id, "Mail", "SendOrder");
            return(resp);
        }
    }