public ImageInfoEntity AddImageInfo(ImageInfoInputModel imageInfo, string freeUrl, string freeSuccess)
        {
            // checking if something went wrong in email sending process
            bool ok        = true;
            bool emailSent = false;

            if (freeSuccess.ToLower() == "sent")
            {
                emailSent = true;
            }
            else
            {
                ok = false;
            }

            // Create the entity to add to the database.
            ImageInfoEntity newEnt = new ImageInfoEntity()
            {
                imageGUID               = imageInfo.imageGUID,
                email                   = imageInfo.email,
                timeStamp               = imageInfo.timeStamp,
                hasFreeEmailBeenSent    = emailSent,
                hasPremiumEmailBeenSent = false,
                success                 = ok,
                hasImageBeenBought      = false,
                premiumUrl              = imageInfo.Url,
                freeUrl                 = freeUrl
            };

            _context.imageInfo.Add(newEnt);
            _context.SaveChanges();
            return(newEnt);
        }
        public ActionResult Save(ProductSold model)
        {
            var result = false;

            try
            {
                if (model.Id > 0)      //Updating
                {
                    ProductSold pro = db.ProductSolds.SingleOrDefault(x => x.Id == model.Id);

                    if (model.ProductId == 0)   //Changes not made for this field --- put a check here isempty isnull (value will be sent null from form if it has not been changed) if valkue is changed in form modal it will apear here
                    {
                        pro.ProductId = pro.ProductId;
                    }
                    else
                    {
                        pro.ProductId = model.ProductId;
                    }
                    if (model.CustomerId == 0)
                    {
                        pro.CustomerId = pro.CustomerId;
                    }
                    else
                    {
                        pro.CustomerId = model.CustomerId;
                    }
                    if (model.StoreId == 0)
                    {
                        pro.StoreId = pro.StoreId;
                    }
                    else
                    {
                        pro.StoreId = model.StoreId;
                    }
                    pro.DateSold        = model.DateSold;
                    db.Entry(pro).State = EntityState.Modified;
                    db.SaveChanges();
                    result = true;
                }
                else     //Adding
                {
                    ProductSold pro = new ProductSold();
                    pro.ProductId  = model.ProductId;
                    pro.CustomerId = model.CustomerId;
                    pro.StoreId    = model.StoreId;
                    pro.DateSold   = model.DateSold;
                    db.ProductSolds.Add(pro);
                    db.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "id,nombre,edad,sexoId")] persona persona)
        {
            if (ModelState.IsValid)
            {
                db.personas.Add(persona);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.sexoId = new SelectList(db.sexos, "id", "Nsexo", persona.sexoId);
            return(View(persona));
        }
Ejemplo n.º 4
0
        public IHttpActionResult SetImagesOrder(IEnumerable <ProjectImages> images)
        {
            foreach (var img in images)
            {
                var DbImage = db.ProjectImages.Where(li => li.Id == img.Id).FirstOrDefault();
                DbImage.SortOrder = img.SortOrder;
            }

            db.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 5
0
 public IActionResult Index(Customer cc)
 {
     try
     {
         var usr   = _dbc.Customer.FromSqlRaw($"SELECT * FROM customer WHERE Username = '******' ");
         var email = _dbc.Customer.FromSqlRaw($"SELECT * FROM customer WHERE Uemail = '{cc.Uemail}' ");
         if (usr.FirstOrDefault() != null)
         {
             ViewBag.message = "The username " + cc.Username + " already exists!";
         }
         else if (email.FirstOrDefault() != null)
         {
             ViewBag.message = "The email " + cc.Uemail + " already exists!";
         }
         else
         {
             cc.Active  = "1";
             cc.Pwd     = Encipher(cc.Pwd, 3);
             cc.enabled = false;
             _dbc.Add(cc);
             _dbc.SaveChanges();
             ViewBag.message = "The User " + cc.Username + " Is Saved Successfully!";
         }
         return(View());
     }
     catch (Exception sqlerror)
     {
         ViewBag.message = sqlerror;
     }
     return(View());
 }
Ejemplo n.º 6
0
        public IActionResult Create(Report r)
        {
            _dbc.Add(r);
            _dbc.SaveChanges();



            return(Redirect("/Home"));
        }
Ejemplo n.º 7
0
        public void CreateBlogResponse(BlogResponse response)
        {
            try
            {
                _context.BlogResponses.Add(response);
                _context.SaveChanges();
            }

            catch (Exception)
            {
            }
        }
Ejemplo n.º 8
0
 public override void OnActionExecuted(System.Web.Http.Filters.HttpActionExecutedContext actionExecutedContext) {
     var principal = actionExecutedContext.ActionContext.RequestContext.Principal;
     if(principal != null) {
         using (var db = new databaseContext()) {
             var dbUser = (from b in db.AspNetUsers
                         where b.UserName == principal.Identity.Name
                         select b).First();
             dbUser.LastActivity = DateTime.Now;
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 9
0
        public BlogEntry CreateBlogEntry(string title, string contents) //string username
        {
            var entry = new BlogEntry
            {
                Title    = title,
                Contents = contents,
                //Author = username,
                //PostedDate = DateTime.Now,
            };

            entry = _context.BlogEntries.Add(entry).Entity;
            _context.SaveChanges();
            return(entry);
        }
Ejemplo n.º 10
0
 public ActionResult EditOffer(Offer offer)
 {
     if (ModelState.IsValid)
     {
         _context.Update(offer);
         _context.SaveChanges();
         return(RedirectToAction(nameof(GetOffer)));
     }
     return(View(offer));
 }
Ejemplo n.º 11
0
        private string checkout()
        {
            var currentUserId = HttpContext.Session.GetInt32("UserId");

            var cart             = _db.Cart.Where(x => x.UserId.Equals(currentUserId)).FirstOrDefault();
            var number_generator = new Random();
            var cartItems        = _db.CartItem.Where(x => x.ShoppingCartId.Equals(cart.CartId)).ToList();
            var OrderID          = number_generator.Next(100000, 999999);

            foreach (var x in cartItems)
            {
                var addOrder = new OrderDetails {
                    ProductId = x.ProductId, Quantity = x.Quantity, UnitPrice = x.ProductPrice, CustomerID = cart.UserId, Discount = 0, TransactionId = OrderID, ProductName = x.ProductTitle
                };
                _db.OrderDetails.Add(addOrder);
                _db.SaveChanges();
                _db.Entry <OrderDetails>(addOrder).State = EntityState.Detached;
            }

            var connectionStringBuilder = new SqliteConnectionStringBuilder();

            connectionStringBuilder.DataSource = "./database.db";
            var connection = new SqliteConnection(connectionStringBuilder.ConnectionString);

            connection.Open();

            var selectCmd = connection.CreateCommand();

            //selectCmd.CommandText = "select * from products where title = '100' or '1' = '1'";
            selectCmd.CommandText = $"delete from CartItem where ShoppingCartId = {cart.CartId}";
            var result = selectCmd.ExecuteNonQuery();

            ViewBag.CheckoutOk = "Successful";

            return(ViewBag.CheckoutOk);
        }
Ejemplo n.º 12
0
 public void Insert(T obj)
 {
     context.Set <T>().Add(obj);
     context.SaveChanges();
 }