public ActionResult FinalizeazaComanda() { var userLogat = Session["UserLogat"].ToString(); var user = _userManager.GetUsers().Where(u => u.UserName == userLogat).FirstOrDefault(); var client = _userManager.GetClientForUsername(user.IdUser); var listaProduseInCos = _cosManager.GetCartProducts(client.IdClient); var model = new FinalizareComandaModel(); model.ListaProduseInCos = listaProduseInCos; var produse = _produsManager.GetProduseComandate().ListaComenzi.Where(x => x.Client.IdClient == client.IdClient).ToList(); model.Adrese = new List <Adresa>(); foreach (var item in produse) { model.Adrese.Add(item.Adresa); } return(View(model)); }
public ActionResult FinalizeazaComanda(FinalizareComandaModel finalizeazaComanda) { var userLogat = Session["UserLogat"].ToString(); var user = _userManager.GetUsers().Where(u => u.UserName == userLogat).FirstOrDefault(); var client = _userManager.GetClientForUsername(user.IdUser); var listaProduseInCos = _cosManager.GetCartProducts(client.IdClient); var sb = new StringBuilder(); decimal total = 0; sb.Append("S-au comandat urmatoarele produse:"); sb.Append(Environment.NewLine); foreach (var produs in listaProduseInCos) { sb.Append(Environment.NewLine); sb.Append("Denumire Produs: " + produs.Produs.NumeProdus + " , " + "Cantitate: " + produs.Cantitate + " , " + "Pret: " + (produs.Produs.PretProdus * produs.Cantitate).ToString("#.##") + " RON"); total = total + produs.Produs.PretProdus; } sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append("TOTAL: " + total.ToString("#.##") + " RON"); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append("Produsele vor fi expediate la adresa: "); sb.Append(Environment.NewLine); sb.Append("Strada: " + finalizeazaComanda.Strada + " , " + "Numar: " + finalizeazaComanda.Numar); sb.Append(Environment.NewLine); sb.Append("Oras: " + finalizeazaComanda.Oras + " , " + "Cod postal: " + finalizeazaComanda.CodPostal + ", " + finalizeazaComanda.Tara); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append("Produsele va for fi livrate in data de: " + DateTime.Now.AddDays(3)); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append("Va multumim!"); var emailBody = sb.ToString(); var adresa = new Adresa() { Strada = finalizeazaComanda.Strada, CodPostal = finalizeazaComanda.CodPostal, Judet = finalizeazaComanda.Judet, Numar = finalizeazaComanda.Numar.ToString(), Oras = finalizeazaComanda.Oras }; var esteComandaAdaugata = _cosManager.AdaugaComanda(adresa, client.IdClient, listaProduseInCos); if (esteComandaAdaugata) { EmailHelper.SendEmail( Constants.EmailFrom, client.Email, Constants.FromName, Constants.EmailTimeStamp + DateTime.Now, emailBody); } return(RedirectToAction("Index", "Home")); }