public ActionResult ChangeBucketItem(int itemId)
        {
            BucketItem bucketItem = new BucketItem();
            BuketListModelWithoutPicture buketListModel = new BuketListModelWithoutPicture();

            using (var session = FluentNHibernateHelper.OpenSession())
            {
                bucketItem = ((List <BucketItem>)session.QueryOver <BucketItem>()
                              .Where(k => k.Id == itemId).List()).ElementAt(0);

                buketListModel.Id           = bucketItem.Id;
                buketListModel.Ime          = bucketItem.Ime;
                buketListModel.KategorijaId = bucketItem.Kategorija.Id.ToString();
                buketListModel.Opis         = bucketItem.Opis;
                buketListModel.Ostvareno    = bucketItem.Ostvareno;
                List <Kategorija> kategorije = (List <Kategorija>)session
                                               .QueryOver <Kategorija>()
                                               .List();
                foreach (var kategorija in kategorije)
                {
                    SelectListItem selectListItem = new SelectListItem();
                    selectListItem.Text  = kategorija.Naziv;
                    selectListItem.Value = kategorija.Id.ToString();
                    buketListModel.kategorijaItems.Add(selectListItem);
                }
            }
            return(View(buketListModel));
        }
        public ActionResult Create(BuketListModel model)
        {
            try
            {
                BucketItem bucketItem = new BucketItem();
                bucketItem.Ime       = model.Ime;
                bucketItem.Ostvareno = model.Ostvareno;

                MemoryStream target = new MemoryStream();
                model.Slika.InputStream.CopyTo(target);
                byte[] data = target.ToArray();
                bucketItem.Slika = data;

                bucketItem.Opis     = model.Opis;
                bucketItem.Korisnik = (Korisnik)Session["User"];

                using (var session = FluentNHibernateHelper.OpenSession())
                {
                    List <Kategorija> kategorija = (List <Kategorija>)session.QueryOver <Kategorija>()
                                                   .Where(k => k.Id == int.Parse(model.KategorijaId)).List();
                    bucketItem.Kategorija = kategorija[0];
                    session.SaveOrUpdate(bucketItem);
                }

                return(RedirectToAction("BucketItems", "Korisnik"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 3
0
            /// <summary>
            /// Raises a callback.
            /// </summary>
            /// <param name="callback"></param>
            public ItemCollection Process(Callback callback)
            {
                if (callback == null)
                {
                    throw new ProviderException(Messages.MustProvideACallback);
                }

                foreach (string key in bucket.Items.Keys)
                {
                    BucketItem item = bucket.Items[key];

                    if (match != null)
                    {
                        if (match.Invoke(item))
                        {
                            callback.Invoke(item);
                        }
                    }
                    else
                    {
                        callback.Invoke(item);
                    }
                }
                // tear down
                match = null;

                return(this);
            }
Ejemplo n.º 4
0
        public virtual int AddItemToBucket(int itemId)
        {
            Product product = _ProductService.GetProductById(itemId);

            BucketItem bucketItem = _BucketItemService.CheckIfExists(Utilities.BucketSelected, itemId);

            if (bucketItem != null)
            {
                bucketItem.Quantity  += 1;
                bucketItem.TotalPrice = bucketItem.Quantity * product.Price;
                _BucketItemService.UpdateBucket(bucketItem);
            }

            else
            {
                bucketItem = new BucketItem();

                bucketItem.BucketId   = Utilities.BucketSelected;
                bucketItem.AddDate    = DateTime.Now;
                bucketItem.ProductId  = itemId;
                bucketItem.UnitPrice  = product.Price;
                bucketItem.Quantity   = 1;
                bucketItem.TotalPrice = product.Price;

                _BucketItemService.InsertBucket(bucketItem);
            }
            Bucket bucket = _BucketService.GetBucketById(Utilities.BucketSelected);

            bucket.BucketAmount += bucketItem.UnitPrice;
            _BucketService.UpdateBucket(bucket);
            return(_BucketItemService.CountItemsByBucketId(Utilities.BucketSelected));
        }
Ejemplo n.º 5
0
        private ItemModel GetItemModel(BucketItem item)
        {
            var model = new ItemModel();

            model.Id   = item.Id;
            model.Text = item.Text;
            return(model);
        }
Ejemplo n.º 6
0
        public void CreatesTheBackingFileOfTheItemIfItDoesNotAlreadyExist()
        {
            Assert.That(File.Exists(BucketItemPath), Is.False);

            BucketItem.Put(123);

            Assert.That(File.Exists(BucketItemPath), Is.True);
        }
Ejemplo n.º 7
0
        public void ReturnsFalseIfTheContentsOfTheItemsFileCannotBeDeserialized()
        {
            CreateBucketItemFile("not an integer");

            int dummy;

            Assert.That(BucketItem.TryGet(out dummy), Is.False);
        }
Ejemplo n.º 8
0
        public void ReturnsTrueIfTheItemsFileExistsAndCanBeDeserialized()
        {
            CreateBucketItemFile(123);

            int dummy;

            Assert.That(BucketItem.TryGet(out dummy), Is.True);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            BucketItem bucketItems = db.BucketItems.Find(id);

            db.BucketItems.Remove(bucketItems);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 10
0
        public string GetFolderPath(Data.ID newItemId, Data.ID parentItemId, DateTime creationDateOfNewItem)
        {
            var bucket = new Types.BucketItem(Sitecore.Context.ContentDatabase.GetItem(parentItemId));

            var dynamicFolderPathResolver = switcher.GetFolderPathResolver(bucket);

            return(dynamicFolderPathResolver.GetFolderPath(BucketItem.Create(newItemId), bucket, creationDateOfNewItem));
        }
Ejemplo n.º 11
0
        public void WhenTheBackingFileOfTheItemDoesNotExistCorrectlyWritesTheContentsOfTheNewFile()
        {
            Assert.That(File.Exists(BucketItemPath), Is.False);

            BucketItem.Put(123);

            Assert.That(GetBucketItemFileContents <int>(), Is.EqualTo(123));
        }
Ejemplo n.º 12
0
        private static void Main(string[] args)
        {
            ServiceManager manager = ServiceManager.Instance;

            Console.WriteLine("Welcome to Ravi's S3 Container");

            List <S3Bucket> buckets = manager.GetBuckets().GetAwaiter().GetResult();

            Console.WriteLine();
            Console.WriteLine("Choose from below S3 containers ...");
            int index = 1;
            Dictionary <string, S3Bucket> bucketsByIndex = new Dictionary <string, S3Bucket>();

            foreach (S3Bucket bucket in buckets)
            {
                bucketsByIndex.Add(index.ToString(), bucket);
                Console.WriteLine($"Press {index} for {bucket.BucketName}");
                index++;
            }

            string   bucketOption = Console.ReadLine();
            S3Bucket _currentBucket;

            while (!bucketsByIndex.TryGetValue(bucketOption, out _currentBucket))
            {
                Console.WriteLine("Invalid key. Please try again");
            }
            Console.WriteLine(_currentBucket.BucketName);

            foreach (ServiceManager.FileMeta fileMeta in manager.GetFileContentByKey())
            {
                BucketItem item = new BucketItem()
                {
                    BucketName = _currentBucket.BucketName,
                    Key        = fileMeta.FolderKey,
                };
                if (manager.SaveItem(item))
                {
                    item = new BucketItem()
                    {
                        BucketName    = _currentBucket.BucketName,
                        Key           = $"{fileMeta.FolderKey}{fileMeta.FileKey}",
                        Base64Content = fileMeta.FileContentBase64String
                    };
                    if (!manager.SaveItem(item))
                    {
                        Console.WriteLine("Failed to upload file");
                    }
                }
                else
                {
                    Console.WriteLine($"Failed to create folder structure");
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 13
0
        public void DeletesTheBackingFileOfTheItem()
        {
            CreateBucketItemFile(123);
            Assert.That(File.Exists(BucketItemPath), Is.True);

            BucketItem.Delete();

            Assert.That(File.Exists(BucketItemPath), Is.False);
        }
Ejemplo n.º 14
0
 public BucketItem UpdateBucket(BucketItem bucketItem)
 {
     if (bucketItem == null)
     {
         throw new ArgumentNullException(nameof(BucketItem));
     }
     _BucketItemRepository.Update(bucketItem);
     return(bucketItem);
 }
Ejemplo n.º 15
0
        public void WhenReturningTrueAssignsTheDeserializedValueOfTheFileToTheOutParameter()
        {
            CreateBucketItemFile(123);

            int value;

            BucketItem.TryGet(out value);

            Assert.That(value, Is.EqualTo(123));
        }
Ejemplo n.º 16
0
        public void WhenTheBackingFileOfTheItemDoesExistCorrectlyOverwritesContentsOfTheExistingFile()
        {
            CreateBucketItemFile(123);

            Assert.That(File.Exists(BucketItemPath), Is.True);

            BucketItem.Put(456);

            Assert.That(GetBucketItemFileContents <int>(), Is.EqualTo(456));
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Created,TargetAmount,CurrentAmount,BucketId")] BucketItem bucketItems)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bucketItems).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BucketId = new SelectList(db.Buckets, "Id", "Name", bucketItems.BucketId);
     return(View(bucketItems));
 }
Ejemplo n.º 18
0
        public BucketItem InsertBucket(BucketItem bucketItem)
        {
            if (bucketItem == null)
            {
                throw new ArgumentNullException(nameof(BucketItem));
            }

            //Bucket.CustomerId = _workContext.CurrentCustomer.Id;
            _BucketItemRepository.Insert(bucketItem);
            return(bucketItem);
        }
Ejemplo n.º 19
0
        private void UploadObject(BucketItem item)
        {
            PutObjectRequest request = new PutObjectRequest();

            request.BucketName = item.BucketName;
            request.Key        = item.Key;
            if (!string.IsNullOrEmpty(item.Base64Content))
            {
                request.ContentBody = item.Base64Content;
            }
            PutObjectResponse response = S3Client.PutObjectAsync(request).GetAwaiter().GetResult();
        }
Ejemplo n.º 20
0
        public async Task <IHttpActionResult> AddOfferToBucketAsync()
        {
            string json = await Request.Content.ReadAsStringAsync();

            dynamic data     = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            string  login    = data["login"];
            int     offerId  = Convert.ToInt32(data["offerId"]);
            string  quantity = data["quantity"];

            User       user          = db.Users.Where(i => i.Login == login).FirstOrDefault();
            BucketItem NewBucketItem = new BucketItem();


            var Offer = db.Offers.Where(i => i.OfferID == offerId && i.IsActive).FirstOrDefault();

            if (Offer != null)//We chceck if user called for existing and active offer
            {
                bool?AlreadyInBucket = user.Bucket?.BucketItems?.Where(i => i.Offer != null && i.Offer.OfferID == offerId).Any();
                if (AlreadyInBucket == false)
                {
                    bool?IsOwner = user.Offers?.Where(i => i.OfferID == offerId).Any();
                    if (IsOwner == false)
                    {
                        if (int.TryParse(quantity, out int QuantityAsInt))
                        {
                            if (Offer.InStockNow < QuantityAsInt || QuantityAsInt < 1)
                            {
                                return(BadRequest("Przekroczono dostępną ilość danego produktu"));
                            }
                            else
                            {
                                NewBucketItem.Offer      = Offer;
                                NewBucketItem.Quantity   = QuantityAsInt;
                                NewBucketItem.TotalPrice = QuantityAsInt * Offer.Price;
                                db.BucketItems.Add(NewBucketItem);

                                user.Bucket.BucketItems.Add(NewBucketItem);
                                NewBucketItem.Bucket = user.Bucket;
                                Offer.BucketItems.Add(NewBucketItem);
                                ConcurencyHandling.SaveChangesWithConcurencyHandling(db);
                                return(Ok("true"));
                            }
                        }
                    }
                    else
                    {
                        return(BadRequest("Już posiadasz tę ofertę"));
                    }
                }
                return(BadRequest("Oferta znajduje sie juz w koszyku"));
            }
            return(BadRequest("Nie udalo sie dodac oferty"));
        }
Ejemplo n.º 21
0
        private bool Validate(BucketItem item)
        {
            var validationResult = bucketitemValidator.Validate(item);

            //loop through error to identify properties
            foreach (var error in validationResult.Errors)
            {
                if (error.PropertyName == nameof(item.ItemDescription))
                {
                    ItemDescriptionError = error.ErrorMessage;
                }
            }
            return(validationResult.IsValid);
        }
        // GET: BucketItems/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BucketItem bucketItems = db.BucketItems.Find(id);

            if (bucketItems == null)
            {
                return(HttpNotFound());
            }
            return(View(bucketItems));
        }
Ejemplo n.º 23
0
            public static BindingBucketItem Convert(BucketItem bucketItem)
            {
                OfferItem         offer = OfferItem.ConvertOfferToOfferItem(bucketItem.Offer);
                BindingBucketItem item  = new BindingBucketItem
                {
                    BucketItemID = bucketItem.BucketItemID,
                    Quantity     = bucketItem.Quantity,
                    TotalPrice   = bucketItem.TotalPrice,
                    IsChosen     = bucketItem.IsChosen,
                    Offer        = offer
                };

                return(item);
            }
Ejemplo n.º 24
0
        public bool SaveItem(BucketItem item)
        {
            List <S3Bucket> buckets = new List <S3Bucket>();
            HttpContent     content = new StringContent(JsonConvert.SerializeObject(item));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = Client.PostAsync("api/s3bucketItem", content).GetAwaiter().GetResult();

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 25
0
        public ActionResult About()
        {
            Korisnik prviKorisnik;

            using (var session = FluentNHibernateHelper.OpenSession())
            {
                List <Korisnik> korisnik = (List <Korisnik>)session.QueryOver <Korisnik>()
                                           .Where(k => k.Id == 4).List();
                prviKorisnik = korisnik.ElementAt(0);
                BucketItem bucketItem = prviKorisnik.BucketItems[0];
            }

            ViewBag.Message = "Your application username: " + prviKorisnik.Username;
            return(View());
        }
Ejemplo n.º 26
0
        public async Task <HttpResponseMessage> Get([FromQuery] BucketItem item)
        {
            GetObjectResponse response = await S3Client.GetObjectAsync(item.BucketName, item.Key);

            HttpResponseMessage responseMessage = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            responseMessage.Content = new StreamContent(response.ResponseStream);
            //responseMessage.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
            //responseMessage.Content.Headers.ContentLength = response.ContentLength;
            foreach (string headerName in response.Headers.Keys)
            {
                responseMessage.Headers.Add(headerName, response.Headers[headerName]);
            }
            return(responseMessage);
        }
Ejemplo n.º 27
0
        private async void deleteItem(object sender, EventArgs e)
        {
            Button     button = (Button)sender;
            BucketItem item   = (BucketItem)button.CommandParameter;
            Dictionary <string, string> model = new Dictionary <string, string>()
            {
                { "login", Session.user.Login },
                { "offerId", (item.Offer.OfferID).ToString() },
            };

            string reponse = await BucketViewModel.DeleteBucketItem(model);

            this.viewModel      = new BucketViewModel();
            this.BindingContext = viewModel;
        }
        // GET: BucketItems/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BucketItem bucketItems = db.BucketItems.Find(id);

            if (bucketItems == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BucketId = new SelectList(db.Buckets, "Id", "Name", bucketItems.BucketId);
            return(View(bucketItems));
        }
        public ActionResult Configure(ConfigureHouseViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user        = db.Users.Find(User.Identity.GetUserId());
                var bankAccount = new BankAccount
                {
                    OwnerId         = user.Id,
                    Name            = model.BankName,
                    Created         = DateTime.Now,
                    StartBal        = model.StartBal,
                    CurrentBal      = model.StartBal,
                    AccountType     = model.AccountType,
                    HouseholdId     = model.HouseholdId,
                    LowBalanceLevel = model.LowBalanceLevel
                };
                db.Accounts.Add(bankAccount);
                db.SaveChanges();
                var bucket = new Bucket
                {
                    CurrentAmount = 0,
                    OwnerId       = user.Id,
                    Created       = DateTime.Now,
                    Name          = model.BucketName,
                    HouseholdId   = model.HouseholdId
                };
                db.Buckets.Add(bucket);
                db.SaveChanges();
                var bucketItem = new BucketItem
                {
                    CurrentAmount = 0,
                    BucketId      = bucket.Id,
                    Name          = model.ItemName,
                    Created       = DateTime.Now,
                    TargetAmount  = model.ItemTargetAmount
                };
                db.BucketItems.Add(bucketItem);

                user.Household.IsConfigured = true;
                db.SaveChanges();
                TempData["Success"] = "Your Household is now configured.";
                return(RedirectToAction("Index", "Home"));
            }
            TempData["Errors"] = ErrorReader.ErrorCompiler(ModelState);
            return(RedirectToAction("Configure", "Households"));
        }
Ejemplo n.º 30
0
        public override void Init(object initData)
        {
            BucketItem item = initData as BucketItem;

            currentItem = item;
            if (item.Id == Guid.Empty)
            {
                PageTitle = "New Item";
            }
            else
            {
                PageTitle = "Edit Item";
            }

            LoadItemState();
            base.Init(initData);
        }
Ejemplo n.º 31
0
 public BucketItemDetail(BucketItem item)
 {
     BindingContext = item;
     InitializeComponent();
 }
Ejemplo n.º 32
0
        private IDictionary<string, BucketItem> CreateItems(Type targetType)
        {
            PropertyInfo[] infos = targetType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            IDictionary<string, BucketItem> list = new Dictionary<string, BucketItem>();

            foreach (PropertyInfo info in infos)
            {
                string fieldName = string.Empty;

                // assume the property is not unique.
                bool isUnique = false;

                object[] arg = info.GetCustomAttributes(typeof(IgnoreAttribute), true);

                if (arg.Length == 0)
                {
                    const bool visible = true;

                    arg = info.GetCustomAttributes(typeof(OriginalNameAttribute), true);

                    if (arg.Length > 0)
                    {
                        var fieldNameAttr = arg[0] as OriginalNameAttribute;

                        if (fieldNameAttr != null)
                            fieldName = fieldNameAttr.Name;
                    }
                    else
                    {
                        fieldName = info.Name;
                    }

                    arg = info.GetCustomAttributes(typeof(PKAttribute), true);

                    if (arg.Length > 0)
                    {
                        isUnique = true;
                    }

                    // only if not already added.
                    if (!list.ContainsKey(info.Name))
                    {
                        var newItem = new BucketItem(targetType, fieldName, info.Name, info.PropertyType, null, isUnique, RelationType.Equal, visible) { };
                        list.Add(info.Name, newItem);
                    }
                }
            }
            return list;
        }