public IHttpActionResult GetAnimalForSale(int SaleID) { try { AnimalForSale animalForSale = new AnimalForSale(); using (UnitOfWork uow = new UnitOfWork()) { animalForSale = uow.AnimalForSaleRepository.Get(x => x.SaleID == SaleID && x.FarmID == FARMID); animalForSale = animalForSale == null ? new AnimalForSale { SaleID = -1 } : animalForSale; var animalProfile = uow.AnimalProfileRepository.GetAll(x => x.FarmID == FARMID).ToList(); return(Ok(new { animalForSale, animalProfile })); } } catch (Exception ex) { throw ex; } }
public void Delete(AnimalForSale entity) { try { entities.AnimalForSales.Remove(entity); } catch (Exception ex) { throw ex; } }
public void Add(AnimalForSale entity) { try { entities.AnimalForSales.Add(entity); } catch (Exception ex) { throw ex; } }
public void Attach(AnimalForSale entity) { try { entities.AnimalForSales.Attach(entity); entities.Entry(entity).State = System.Data.Entity.EntityState.Modified; } catch (Exception ex) { throw ex; } }
public void Save(AnimalForSale entity) { try { AnimalForSale animalForSale = entities.AnimalForSales .Where(x => x.SaleID == entity.SaleID).FirstOrDefault(); if (animalForSale != null) { entities.Entry(animalForSale).State = EntityState.Modified; } else { Add(entity); } } catch (Exception ex) { throw ex; } }
public IHttpActionResult Save(AnimalForSaleVM animalForSaleVm) { try { AnimalForSale animalForSale = new AnimalForSale(); using (UnitOfWork uow = new UnitOfWork()) { if (animalForSaleVm.SaleID == -1) { animalForSale = new AnimalForSale(); animalForSale.CreatedBy = "ADMIN"; animalForSale.CreatedOn = DateTime.UtcNow; } else { animalForSale = uow.AnimalForSaleRepository.Get(x => x.AnimalCode == animalForSaleVm.AnimalCode); animalForSale.ModifiedBy = "ADMIN"; animalForSale.ModifiedOn = DateTime.UtcNow; } animalForSale.FarmID = FARMID; animalForSale.AnimalCode = animalForSaleVm.AnimalCode; animalForSale.AnimalAge = animalForSaleVm.AnimalAge; animalForSale.Breed = animalForSaleVm.Breed; animalForSale.SireCode = animalForSaleVm.SireCode; animalForSale.BreederCode = animalForSaleVm.BreederCode; animalForSale.Talents = animalForSaleVm.Talents; animalForSale.Weight = animalForSaleVm.Weight; animalForSale.FightingRecord = animalForSaleVm.FightingRecord; animalForSale.IsShowStandardPrice = animalForSaleVm.IsShowStandardPrice; animalForSale.IsActive = animalForSaleVm.IsActive; var myfilename = string.Format(@"{0}{1}", Guid.NewGuid(), ".jpeg"); if (animalForSaleVm.FileName != null && animalForSaleVm.FileName.Length > 0) { animalForSale.AnimalPhoto = myfilename; } uow.AnimalForSaleRepository.Save(animalForSale); uow.SaveChanges(); if (animalForSaleVm.FileName != null && animalForSaleVm.FileName.Length > 0) { string path = System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads/" + animalForSale.FarmID + "/AnimalForSale/" + animalForSale.SaleID + "/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filepath = path + myfilename; var bytess = Convert.FromBase64String(animalForSaleVm.FileName); using (var imageFile = new FileStream(filepath, FileMode.Create)) { imageFile.Write(bytess, 0, bytess.Length); imageFile.Flush(); } } return(Ok(new { })); } } catch (Exception ex) { throw ex; } }