Exemplo n.º 1
0
        public async Task <IActionResult> PutHaul(int id, Haul haul)
        {
            if (id != haul.HaulId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> Delete(string partitionkey, string rowkey)
        {
            if (rowkey == null)
            {
                return(NotFound());
            }
            if (partitionkey == null)
            {
                return(NotFound());
            }

            CloudStorageAccount storage     = connectionstrg();
            CloudTableClient    tableclient = storage.CreateCloudTableClient();
            CloudTable          table       = tableclient.GetTableReference("HaulTable");

            TableOperation retrieveOperation = TableOperation.Retrieve <Haul>(partitionkey, rowkey);

            TableResult result = await table.ExecuteAsync(retrieveOperation);

            Haul hauls = new Haul();

            if (result.Result != null)
            {
                hauls = ((Haul)result.Result);
            }

            return(View(hauls));
        }
        public async Task <IActionResult> Edit([Bind("PartitionKey, RowKey, category, clothes, brand, description, UserId")] Haul haul)
        {
            if (ModelState.IsValid)
            {
                CloudStorageAccount storage     = connectionstrg();
                CloudTableClient    tableclient = storage.CreateCloudTableClient();
                CloudTable          table       = tableclient.GetTableReference("HaulTable");

                Haul hauls = new Haul(haul.PartitionKey, haul.RowKey);
                hauls.clothes     = haul.clothes;
                hauls.brand       = haul.brand;
                hauls.description = haul.description;
                hauls.UserId      = haul.UserId;
                hauls.ETag        = "*";

                // Update the details into table storage.
                TableOperation UpdateOperation = TableOperation.Replace(hauls);

                // Execute the update operation.
                await table.ExecuteAsync(UpdateOperation);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(haul));
        }
        public async Task <IActionResult> Create([Bind("category, clothes, brand, description, UserId")] Haul haul)
        {
            ViewBag.userid = _userManager.GetUserId(HttpContext.User);
            if (ModelState.IsValid)
            {
                CloudStorageAccount storage     = connectionstrg();
                CloudTableClient    tableClient = storage.CreateCloudTableClient();
                CloudTable          table       = tableClient.GetTableReference("HaulTable");
                string rowkey = Guid.NewGuid().ToString("N");
                Haul   hauls  = new Haul(haul.category, rowkey);
                hauls.clothes     = haul.clothes;
                hauls.brand       = haul.brand;
                hauls.description = haul.description;
                hauls.UserId      = haul.UserId;

                // Create the TableOperation that inserts the customer entity.
                TableOperation insertOperation = TableOperation.Insert(hauls);

                // Execute the insert operation.
                await table.ExecuteAsync(insertOperation);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(haul));
        }
Exemplo n.º 5
0
        public async Task <ActionResult <Haul> > PostHaul(Haul haul)
        {
            try
            {
                //Haul Table
                if (haul.HaulId == 0)
                {
                    _context.Haul.Add(haul);
                }
                else
                {
                    _context.Entry(haul).State = EntityState.Modified;
                }

                //ActiveHaul Table
                foreach (var item in haul.ActiveHaul)
                {
                    if (item.ActiveHaulId == 0)
                    {
                        _context.ActiveHaul.Add(item);
                    }
                    else
                    {
                        _context.Entry(item).State = EntityState.Modified;
                    }
                }
                //Delete for ActiveHaul
                foreach (var id in haul.DeletedActiveHaulIDs.Split(',').Where(x => x != ""))
                {
                    ActiveHaul x = _context.ActiveHaul.Find(Convert.ToInt32(id));
                    _context.ActiveHaul.Remove(x);
                }
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void SubmitHaulData(int landingSiteId, int vesselId, DateTime sampleDateTime, DateTime haulDateTime, DateTime?trapSetTime, int numberOfFisherman, string notes, decimal?longitude, decimal?latitude, decimal haulWeight, decimal sampleWeight, string fishType, int[] gear)
        {
            var haul = new Haul()
            {
                LandingSiteId     = landingSiteId,
                VesselId          = vesselId,
                SamplingDateTime  = sampleDateTime,
                HaulDateTime      = haulDateTime,
                TrapSetDateTime   = trapSetTime,
                NumberOfFisherman = numberOfFisherman,
                Notes             = notes,
                Longitude         = longitude,
                Latitude          = latitude,
                HaulWeight        = haulWeight,
                SampleWeight      = sampleWeight
            };

            using (var dal = new HackathonEntities())
            {
                dal.Hauls.Add(haul);

                if (dal.SaveChanges() == 0)
                {
                    throw new WebFaultException <string>("Data not saved", HttpStatusCode.InternalServerError);
                }
            }

            //try
            //{

            //}
            //catch (Exception ex)
            //{
            //    throw new WebFaultException<string>("Bar wasn't Foo'd", HttpStatusCode.BadRequest);
            //    return (int)HttpStatusCode.InternalServerError;
            //}
        }