public void EditFalcon(NewFalcon falcon)
        {
            var _falcon = _db.NewFalcon.Include(a => a.Species).Include(a => a.ScientificName).Include(a => a.Gender)
                          .Include(a => a.Status).Include(a => a.Colors).Include(a => a.Seasons).FirstOrDefault(m => m.Id == falcon.Id);

            if (_falcon != null)
            {
                _falcon.RingNumber   = falcon.RingNumber;
                _falcon.ChipNumber   = falcon.ChipNumber;
                _falcon.FalconTypeId = falcon.FalconTypeId;
                _falcon.NameTypeId   = falcon.NameTypeId;
                _falcon.GenderId     = falcon.GenderId;
                _falcon.StatusId     = falcon.StatusId;
                _falcon.ColorId      = falcon.ColorId;
                _falcon.Width        = falcon.Width;
                _falcon.Length       = falcon.Length;
                _falcon.Weight       = falcon.Weight;
                _falcon.SeasonId     = falcon.SeasonId;
                _falcon.GiftedTo     = falcon.GiftedTo;
                _falcon.FrontImage   = falcon.FrontImage;
                _falcon.BackImage    = falcon.BackImage;
                _falcon.Notes        = falcon.Notes;
                _falcon.Documents    = falcon.Documents;
                _falcon.UpdatedOn    = DateTime.Now;
            }
            _db.NewFalcon.Update(_falcon);
            _db.SaveChanges();
        }
 public void AddFalcon(NewFalcon falcon)
 {
     if (falcon != null)
     {
         NewFalcon falcons = new NewFalcon
         {
             RingNumber   = falcon.RingNumber,
             ChipNumber   = falcon.ChipNumber,
             FalconTypeId = falcon.FalconTypeId,
             NameTypeId   = falcon.NameTypeId,
             GenderId     = falcon.GenderId,
             StatusId     = falcon.StatusId,
             ColorId      = falcon.ColorId,
             Width        = falcon.Width,
             Length       = falcon.Length,
             Weight       = falcon.Weight,
             SeasonId     = falcon.SeasonId,
             GiftedTo     = falcon.GiftedTo,
             FrontImage   = falcon.FrontImage,
             BackImage    = falcon.BackImage,
             Notes        = falcon.Notes,
             Documents    = falcon.Documents,
             CreatedOn    = DateTime.Now,
             CreatedBy    = falcon.CreatedBy,
             UpdatedBy    = falcon.UpdatedBy
         };
         _db.NewFalcon.Add(falcons);
         _db.SaveChanges();
     }
 }
Exemple #3
0
        public IActionResult Create(NewFalcon addFalcon)
        {
            string webRootPath = _hostingEnvironment.WebRootPath;
            var    files       = HttpContext.Request.Form.Files;

            if (FalconVModel.NewFalcon.FrontImg != null)
            {
                var frontPath  = Path.Combine(webRootPath, SD.ImageFolder);
                var fileName   = Guid.NewGuid().ToString().Replace("-", "");
                var extenstion = Path.GetExtension(FalconVModel.NewFalcon.FrontImg.FileName);
                using (var filestram = new FileStream(Path.Combine(frontPath, fileName + extenstion), FileMode.Create))
                {
                    FalconVModel.NewFalcon.FrontImg.CopyTo(filestram);
                    FalconVModel.NewFalcon.FrontImage = @"\" + SD.ImageFolder + @"\" + fileName + extenstion;
                }
            }
            if (FalconVModel.NewFalcon.BackImg != null)
            {
                var frontPath  = Path.Combine(webRootPath, SD.ImageFolder);
                var fileName   = Guid.NewGuid().ToString().Replace("-", "");
                var extenstion = Path.GetExtension(FalconVModel.NewFalcon.BackImg.FileName);
                using (var filestram = new FileStream(Path.Combine(frontPath, fileName + extenstion), FileMode.Create))
                {
                    FalconVModel.NewFalcon.BackImg.CopyTo(filestram);
                    FalconVModel.NewFalcon.BackImage = @"\" + SD.ImageFolder + @"\" + fileName + extenstion;
                }
            }
            if (FalconVModel.NewFalcon.DocumentImg != null)
            {
                var frontPath  = Path.Combine(webRootPath, SD.ImageFolder);
                var fileName   = Guid.NewGuid().ToString().Replace("-", "");
                var extenstion = Path.GetExtension(FalconVModel.NewFalcon.DocumentImg.FileName);
                using (var filestram = new FileStream(Path.Combine(frontPath, fileName + extenstion), FileMode.Create))
                {
                    FalconVModel.NewFalcon.DocumentImg.CopyTo(filestram);
                    FalconVModel.NewFalcon.Documents = @"\" + SD.ImageFolder + @"\" + fileName + extenstion;
                }
            }

            _db.AddFalcon(FalconVModel.NewFalcon);
            return(RedirectToAction(nameof(Index)));
        }