public async Task <CropGroup> AddCropGroupAsync(CropGroup cropGroup)
        {
            _context.Add(cropGroup);
            await _context.SaveChangesAsync();

            return(cropGroup);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Update(int id, CropGroup cropGroup)
        {
            if (id != cropGroup.CropGroupId)
            {
                return(BadRequest());
            }

            _context.Entry(cropGroup).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <CropGroup> > Create(CropGroup cropGroup)
        {
            if (string.IsNullOrWhiteSpace(cropGroup.CropGroupName))
            {
                return(BadRequest());
            }

            _context.CropGroups.Add(cropGroup);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetById), new { id = cropGroup.CropGroupId }, cropGroup));
        }
Ejemplo n.º 4
0
        private async Task TestUpdateCropGroup(CropGroup cropGroup)
        {
            try
            {
                await _cropGroupRepository.UpdateCropGroupAsync(cropGroup);

                richTextBoxLog.Text += $"{cropGroup.CropGroupId}: {cropGroup.CropGroupName}\n";
            }
            catch (Exception exc)
            {
                richTextBoxLog.Text += $"{exc.Message}\n";
            }
        }
Ejemplo n.º 5
0
        private async Task TestCreateCropGroup(CropGroup cropGroup)
        {
            try
            {
                CropGroup addedCropGroup = await _cropGroupRepository.AddCropGroupAsync(cropGroup);

                richTextBoxLog.Text += $"{addedCropGroup.CropGroupId}: {addedCropGroup.CropGroupName}\n";
            }
            catch (Exception exc)
            {
                richTextBoxLog.Text += $"{exc.Message}\n";
            }
        }
Ejemplo n.º 6
0
        /// <summary>Creates the cropGroup.</summary>
        /// <param name="cropGroup">The cropGroup.</param>
        /// <returns>A JSON encoded success indicator</returns>
        public JsonResult Create(CropGroup cropGroup)
        {
            try
            {
                var farmContext = new PicolEntities();
                farmContext.CropGroups.Add(cropGroup);
                farmContext.SaveChanges();

                return(new JsonNetResult {
                    Data = new { Error = false, CropGroup = cropGroup }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            catch (Exception e)
            {
                // Signal the error to be logged by elmah
                ErrorSignal.FromCurrentContext().Raise(e);
                return(new JsonNetResult {
                    Data = new { Error = true, ErrorMessage = "Failed save cropGroup." }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }
Ejemplo n.º 7
0
        /// <summary>Updates the cropGroup.</summary>
        /// <param name="cropGroup">The cropGroup.</param>
        /// <returns>A JSON encoded success indicator</returns>
        public JsonResult Update(CropGroup cropGroup)
        {
            try
            {
                var farmContext = new PicolEntities();
                farmContext.CropGroups.Attach(cropGroup);
                farmContext.Entry(cropGroup).State = System.Data.Entity.EntityState.Modified;
                farmContext.SaveChanges();

                return(new JsonNetResult {
                    Data = new { Error = false }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            catch (Exception e)
            {
                // Signal the error to be logged by elmah
                ErrorSignal.FromCurrentContext().Raise(e);
                return(new JsonNetResult {
                    Data = new { Error = true, ErrorMessage = "Failed to update cropGroup." }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }
 public async Task UpdateCropGroupAsync(CropGroup cropGroup)
 {
     _context.Update(cropGroup);
     await _context.SaveChangesAsync();
 }
 public async Task RemoveCropGroupAsync(CropGroup cropGroup)
 {
     _context.Remove(cropGroup);
     await _context.SaveChangesAsync();
 }