Exemplo n.º 1
0
        public IActionResult EditCar(CarItem modell, IFormFile filePath)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (filePath != null)
                    {
                        modell.TitleImagePath = filePath.FileName;
                        using (var stream =
                                   new FileStream(Path.Combine(_hostingEnv.WebRootPath, "img/cars/", filePath.FileName),
                                                  FileMode.Create))
                        {
                            filePath.CopyTo(stream);
                        }
                    }

                    _dataManager.CarItems.SaveCar(modell);
                    return(RedirectToAction(nameof(EditVehicleController.IndexCar),
                                            nameof(EditVehicleController).CutController()));
                }
                catch (Exception)
                {
                    ViewBag.Brands = _dataManager.BrandItems.GetBrandItems();
                    ViewBag.Except = true;
                    return(View(modell));
                }
            }
            ViewBag.Brands = _dataManager.BrandItems.GetBrandItems();
            return(View(modell));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutCarItem(long id, CarItem carItem)
        {
            if (id != carItem.Id)
            {
                return(BadRequest("The car with this ID does not exist!"));
            }
            if (carItem.Year < 2000)
            {
                return(BadRequest("Year must be greater than 2000"));
            }
            else if (carItem.Price < 100)
            {
                return(BadRequest(" The price must be greater than 100"));
            }

            _context.Entry(carItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public IActionResult Create(CarItem item)
        {
            _context.CarItems.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetCar", new { id = item.Id }, item));
        }
Exemplo n.º 4
0
 private void SaveImagesAndLink(CarItem dbModel, IEnumerable <HttpPostedFileBase> files)
 {
     //save images into db
     if (files == null)
     {
         return;
     }
     foreach (var file in files)
     {
         if (file == null || file.ContentLength <= 0)
         {
             continue;
         }
         var image = new CarImages
         {
             Name          = file.FileName,
             ContentLength = file.ContentLength,
             ContentType   = file.ContentType,
             Data          = new byte[file.ContentLength]
         };
         file.InputStream.Read(image.Data, 0, (int)image.ContentLength);
         _carImageManager.Add(image);  //save image to db
         dbModel.CarImages.Add(image); //add link to CarItem
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Adds an item to cart.
 /// </summary>
 /// <param name="item">Item.</param>
 public void AddToCart(CarItem item, int count)
 {
     if (this.shoppingCart != null)
     {
         this.shoppingCart.Add(item.Barcode, count);
     }
 }
        //[ResponseType(typeof(List<CarItem>))]
        public CarItem getMyCar()
        {
            var    userIdentity = System.Web.HttpContext.Current.User.Identity;
            string loggedInUser = userIdentity.GetUserId().ToString();


            Car car = db.Cars.Where(loc => loc.UserNameId == loggedInUser)
                      .FirstOrDefault();
            CarItem carItem = new CarItem();

            if (car == null)
            {
                return(carItem);
            }
            else
            {
                carItem.title         = car.Title;
                carItem.description   = car.Description;
                carItem.aLong         = car.Long;
                carItem.lat           = car.Lat;
                carItem.carPhoto      = car.CarPhoto;
                carItem.price         = car.Price;
                carItem.availableFrom = car.AvailableFrom;
                carItem.availableTo   = car.AvailableTo;
                carItem.userNameId    = car.UserNameId;
                carItem.contactNumber = car.ContactNumber;
            }
            return(carItem);
        }
Exemplo n.º 7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            var shirts = Tshirts.not_expired();
            polosRepeater.DataSource = shirts;
            polosRepeater.DataBind();
        }
        else
        {
            // Se agrega al carrito
            int idShirt = int.Parse(item.Value);
            CarItem it = new CarItem(idShirt);

            if (Session["cart"] != null)
            {
                List<CarItem> cart = (List<CarItem>)Session["cart"];

                var repeated = cart.FindAll(i =>
                    i.shirt.id == idShirt);

                if (repeated.Count > 0)
                {
                    repeated.First().add(1);
                }
                else
                {
                    cart.Add(it);
                }
                Response.Redirect("Carrito.aspx");
            }
        }
    }
Exemplo n.º 8
0
        public async Task <IActionResult> PutCarItem(long id, CarItem carItem)
        {
            if (id != carItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(carItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 9
0
        public ActionResult DeleteConfirmed(int id)
        {
            CarItem caritem = db.CarItems.Find(id);

            db.CarItems.Remove(caritem);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 10
0
        public async Task <bool> AddCarItemAsync(CarItem newCarItem)
        {
            newCarItem.Id = Guid.NewGuid();
            _context.Items.Add(newCarItem);
            var saveResult = await _context.SaveChangesAsync();

            return(saveResult == 1);
        }
Exemplo n.º 11
0
        public IActionResult AddCar()
        {
            CarItem vehicle = new CarItem();

            ViewBag.Brands = _dataManager.BrandItems.GetBrandItems();
            ViewBag.Except = false;
            return(View(vehicle));
        }
Exemplo n.º 12
0
        private void When(CarItemAddedEvent @event) =>
        With(this, state =>
        {
            var newItem = CarItem.Create(new CarItemId(@event.CarItemId), @event.CarId, @event.Desciption);

            state._carItems = state._carItems ?? new List <CarItemState>();

            state._carItems.Add(newItem.State);
        });
Exemplo n.º 13
0
        public void RestoreSnapshot(object state)
        {
            var snapshot = (CarStateSnapshot)state;

            this.Id        = new CarId(snapshot.Id);
            this._name     = snapshot.Name;
            this.Year      = snapshot.Year;
            this._carItems = this._carItems ?? new List <CarItemState>();
            this._carItems = snapshot.CarItems?.Select(c => CarItem.Create(c.Id, new CarId(c.CarId), c.Desciption).State).ToList() ?? this._carItems;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Adds a new item to database.
        /// </summary>
        /// <param name="carItem">Car item.</param>
        public void AddNewItemToDatabase(CarItem carItem)
        {
            long barcode = carItem.Barcode;

            if (!barcodes.Contains(barcode))
            {
                this.barcodes.Add(barcode);
                this.database.Add(barcode, carItem);
            }
        }
Exemplo n.º 15
0
        //
        // GET: /CarItem/Details/5

        public ActionResult Details(int id = 0)
        {
            CarItem caritem = db.CarItems.Find(id);

            if (caritem == null)
            {
                return(HttpNotFound());
            }
            return(View(caritem));
        }
Exemplo n.º 16
0
        //
        // GET: /CarItem/Edit/5

        public ActionResult Edit(int id = 0)
        {
            CarItem caritem = db.CarItems.Find(id);

            if (caritem == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CarID     = new SelectList(db.Cars, "CarID", "Model", caritem.CarID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Image", caritem.ProductID);
            return(View(caritem));
        }
Exemplo n.º 17
0
 public void SaveCar(CarItem entity)
 {
     if (entity.Id == default)
     {
         context.Entry(entity).State = EntityState.Added;
     }
     else
     {
         context.Entry(entity).State = EntityState.Modified;
     }
     context.SaveChanges();
 }
Exemplo n.º 18
0
 public ActionResult Edit(CarItem caritem)
 {
     if (ModelState.IsValid)
     {
         db.Entry(caritem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CarID     = new SelectList(db.Cars, "CarID", "Model", caritem.CarID);
     ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Image", caritem.ProductID);
     return(View(caritem));
 }
Exemplo n.º 19
0
        public async Task <bool> AddNewCarItemAsync(CarItem data, string userId)
        {
            if (await _db.CarEntities.AnyAsync(x => x.UserId == userId && x.Id == data.CarEntityId))
            {
                await _db.CarItems.AddAsync(data);

                await _db.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
Exemplo n.º 20
0
        private void DeleteImages(CarItem dbItem, IEnumerable <int> ids)
        {
            var dbImagesArrayForDelete = dbItem.CarImages.Where(x => ids.Contains(x.Id)).ToList();

            foreach (var item in dbImagesArrayForDelete)
            {
                //remove from dbitem
                dbItem.CarImages.Remove(item);
                //remove from database
                _carImageManager.Delete(item);
            }
        }
Exemplo n.º 21
0
        public async Task <ActionResult <CarItem> > PostCarItem(CarItem carItem)
        {
            if (carItem.Year < 0)
            {
                return(BadRequest("Invalid value entered for 'year' field!"));
            }

            _context.CarItems.Add(carItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCarItem), new { id = carItem.Id }, carItem)); // TODO ask about the return
        }
Exemplo n.º 22
0
        /// <summary>
        /// Generates the random car item.
        /// </summary>
        /// <returns>The random car item.</returns>
        public CarItem GenerateRandomCarItem()
        {
            string  name          = GenerateRandomName();
            int     code          = GenerateRandomeCode();
            double  price         = GenerateRandomPrice();
            int     quantity      = GenerateRandomQuantity();
            double  discount      = GenerateRandomDiscount();
            CarItem randomCarItem = new CarItem(name, code, price, quantity);

            randomCarItem.SetDiscount(discount);
            return(randomCarItem);
        }
Exemplo n.º 23
0
        public async Task <IActionResult> PostCarItem([FromBody] CarItem carItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.CarItem.Add(carItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCarItem", new { id = carItem.Id }, carItem));
        }
Exemplo n.º 24
0
        public async Task <CarItem> CreateAsync(CarItem car)
        {
            using (var conn = await GetOpenConnectionAsync())
            {
                car.Id        = Guid.NewGuid();
                car.CreatedOn = DateTime.Now;
                car.UpdatedOn = DateTime.Now;

                conn.Insert(car);
            }
            return(car);
        }
Exemplo n.º 25
0
        public ActionResult Create(CarItem caritem)
        {
            if (ModelState.IsValid)
            {
                db.CarItems.Add(caritem);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CarID = new SelectList(db.Cars, "CarID", "Model", caritem.CarID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Image", caritem.ProductID);
            return View(caritem);
        }
Exemplo n.º 26
0
        public ActionResult Create(CarItem caritem)
        {
            if (ModelState.IsValid)
            {
                db.CarItems.Add(caritem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CarID     = new SelectList(db.Cars, "CarID", "Model", caritem.CarID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Image", caritem.ProductID);
            return(View(caritem));
        }
Exemplo n.º 27
0
        public async Task <IActionResult> AddItem(CarItem newCarItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var successful = await _carItemService.AddCarItemAsync(newCarItem);

            if (!successful)
            {
                return(BadRequest("Could not add item."));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 28
0
 public async Task <IEnumerable <CarItem> > UpsertAsync(CarItem car)
 {
     using (var conn = await GetOpenConnectionAsync())
     {
         return(await conn.QueryAsync <CarItem>(
                    param : new
         {
             Id = car.Id,
             Brand = car.Brand,
             Model = car.Model,
         },
                    sql : SpUpdate,
                    commandType : CommandType.StoredProcedure));
     }
 }
Exemplo n.º 29
0
        public async Task <ActionResult> AjaxForm()
        {
            var lstCate = _dnUnitApi.GetAllList();

            ViewBag.lstCate = lstCate;
            var model = new CarItem()
            {
            };

            if (DoAction == ActionType.Edit)
            {
                model = await _carApi.GetById(ArrId.FirstOrDefault());
            }
            ViewBag.Action = DoAction;
            return(View(model));
        }
Exemplo n.º 30
0
        public async Task <ActionResult> Actions()
        {
            var msg = new JsonMessage {
                Erros = false
            };
            var url   = Request.Form.ToString();
            var lstID = string.Join(",", ArrId);

            switch (DoAction)
            {
            case ActionType.Add:
                var request = new CarItem();
                UpdateModel(request);
                var result = await _carApi.Add(request);

                if (result.Erros)
                {
                    msg.Erros   = true;
                    msg.Message = result.Message;
                    break;
                }
                msg.Message = "Cập nhật dữ liệu thành công !";
                break;

            case ActionType.Edit:
                var requestUpdate = new CarItem();
                UpdateModel(requestUpdate);

                await _carApi.Update(requestUpdate);

                msg.Message = "Cập nhật dữ liệu thành công !";
                break;

            case ActionType.Delete:
                await _carApi.Delete(ArrId.FirstOrDefault());

                msg.Message = "Cập nhật thành công.";
                break;
            }
            if (string.IsNullOrEmpty(msg.Message))
            {
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 31
0
 private void AddAction()
 {
     if (!IsBusy)
     {
         IsBusy = true;
         var item = new CarItem
         {
             Brand = Brand,
             Line  = Line,
             Year  = Year
         };
         //var checkItem = ItemCars.FirstOrDefault(x => x == item);
         //if
         ItemCars.Add(item);
         IsBusy = false;
     }
 }
        public CarItemViewModel CopyFields(CarItem from, CarItemViewModel to)
        {
            if (to == null)
            {
                throw new NullReferenceException();
            }
            if (from == null)
            {
                throw new NullReferenceException();
            }
            to.Id          = from.Id;
            to.BodyTypeId  = from.BodyTypeId;
            to.ModelId     = from.ModelId;
            to.Description = from.Description;
            to.CarBodyType = from.CarBodyType?.Name;
            to.OwnerId     = from.OwnerId;
            if (@from.CarModel != null)
            {
                to.CarModel       = from.CarModel.Name;
                to.ManufacturerId = @from.CarModel.ManufacturerId;
                to.Manufacturer   = @from.CarModel.Manufacturer?.Name;
                to.CountryId      = @from.CarModel.Manufacturer?.CountryId;
                to.Country        = @from.CarModel.Manufacturer?.Country?.Name;
            }
            to.SelectedCarOptions = new string[from.CarOption.Count];
            var arrayCo = new CarOption[from.CarOption.Count];

            from.CarOption.CopyTo(arrayCo, 0);
            for (var i = 0; i < from.CarOption.Count; i++)
            {
                to.SelectedCarOptions[i] = arrayCo[i].Id.ToString();
            }
            to.EditDate          = from.EditDate;
            to.LastEditorId      = from.LastEditorId;
            to.LastEditorName    = from.AspNetUsers1.UserName;
            to.FuelTypeId        = from.FuelTypeId;
            to.FuelType          = from.FuelType?.Name;
            to.TransmitionTypeId = from.TransmitionTypeId;
            to.TransmitionType   = from.TransmitionType?.Name;
            to.Price             = from.Price;
            to.Volume            = from.Volume;
            to.Status            = (CarItemStatus)from.Status;
            to.ReleaseYear       = from.ReleaseYear;
            return(to);
        }
Exemplo n.º 33
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            int id;
            if (int.TryParse(Request.Params["id"], out id))
            {
                var polo = Tshirts.find(id);

                if (polo != null)
                {
                    item.Value = polo.id.ToString();
                    foto.ImageUrl = polo.imagen;
                    nombre.Text = polo.name;
                    precio.Text = polo.price.ToString();
                    descripcion.Text = polo.description;
                    expirein.Value = ((DateTime)polo.expire_time).ToShortDateString();
                }
            }

        }
        else
        {
            int idShirt = int.Parse(item.Value);
            CarItem it = new CarItem(idShirt);

            if (Session["cart"] != null)
            {
                List<CarItem> cart = (List<CarItem>)Session["cart"];

                var repeated = cart.FindAll(i =>
                    i.shirt.id == idShirt);

                if (repeated.Count > 0)
                {
                    repeated.First().add(1);
                }
                else
                {
                    cart.Add(it);
                }
                Response.Redirect("Carrito.aspx");
            }
        }
    }
Exemplo n.º 34
0
 public ActionResult Edit(CarItem caritem)
 {
     if (ModelState.IsValid)
     {
         db.Entry(caritem).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CarID = new SelectList(db.Cars, "CarID", "Model", caritem.CarID);
     ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Image", caritem.ProductID);
     return View(caritem);
 }