public ActionResult CreateUpdateSeed(SeedModel seedModel) { if (!ModelState.IsValid) { return(ShowErrorMessage(GetModelErrors(ModelState))); } if (!CheckEmployeeHasBalance(seedModel.TotalPricePer)) { return(ShowErrorMessage(Constant.InsufficientBalance)); } var seed = new Seed(); if (seedModel.Id > 0) { seed = FarmManagementEntities.Seeds.Single(x => x.Id == seedModel.Id); } seed.FarmId = seedModel.FarmId; seed.VendorId = seedModel.VendorId; seed.AccountId = seedModel.AccountId; seed.CropId = seedModel.CropId; seed.DatePurchase = seedModel.DatePurchase; seed.OtherDescription = seedModel.OtherDescription; seed.Quality = seedModel.SeedQuality.ToNullIfEmptyEnum <Quality>(); seed.Quantity = seedModel.SeedQuantity.ToNullIfEmptyEnum <Quantity>(); var fileUpload = ClientSession.FileUploads.Single(x => x.FileUploadGuid == seedModel.SeedGuid && x.FileUploadName == FileUploadPath.Seed && !x.HasRemoved); seed.PaymentBill = System.IO.Path.GetFileName(fileUpload.FilePath); if (seedModel.Id == 0) { seed.TotalPricePer = seedModel.TotalPricePer; seed.PricePerItem = seedModel.PricePerItem; seed.QuantityInNumber = seedModel.QuantityInNumber; seed.InsertDate = DateTime.Now; seed.UserId = seedModel.UserId; FarmManagementEntities.Seeds.Add(seed); ManageEmployeeBalance(seedModel.TotalPricePer); } else { seed.UpdateDate = DateTime.Now; } FarmManagementEntities.SaveChanges(); UpdateFileUploadPath(FileUploadPath.Seed, fileUpload, seed.Id); ClearAllFileUpload(); var message = string.Format(Constant.SuccessMessage, seedModel.Id > 0 ? "updated" : "added"); return(ShowSuccessMessage(message)); }
public SeedManagementViewModel(SeedModel.IDataAccessService servPxy) { dataAccessService = servPxy; AddSeedCommand = new RelayCommand(SaveSeed); DeleteSeedCommand = new RelayCommand<Seed>(DeleteSeed); NewSeed = new Seed(); SeedList = dataAccessService.GetSeeds(); }
public void init(float x, float y, GameManager gm) { this.transform.position = new Vector3(x, y, 0); this.gm = gm; this.name = "Seed"; GameObject modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad); // Create a quad object for holding the bird texture. model = modelObject.AddComponent <SeedModel> (); // Add a bird_model script to control visuals of the bird. model.init(this); }
public void CreateSeed(PollenModel pollen) { float direction = UnityEngine.Random.Range(0, 360f); launch.transform.eulerAngles = new Vector3(0, direction, 0); SeedModel seed = Pollinate(pollen); if (seed != null) { Controller.Instantiate <SeedController>("seed", seed, GameManager.instance.seeds.transform); } model.pollen = false; }
/// <summary> /// POST: api/Seed /// Save the seed image and generate seed id . Resuse exisiting seed if already added /// <param name="seedModel">Seed to add</param> /// </summary> public HttpResponseMessage Post([FromBody] SeedModel seedModel) { ISeed seed = new Seed { SourceImageUrl = seedModel.image.IndexOf("http", StringComparison.Ordinal) >= 0 ? seedModel.image : "", Height = seedModel.height, Width = seedModel.width }; // Get the bytes of the image (Download from URL or load from base 64 data) seed.ImageData = imageManager.GetImageData(seedModel.image); // Check if seed already exists by generating a hash and checking against the repository seed.ImageHash = imageManager.ImageHash(seed.ImageData, seedModel.width, seedModel.height); // Check this seed image already exists var existingSeed = repository.GetSeedByHash(seed.ImageHash); // Add the seed if it does not already exist, otherwose continue with the existing seed image if (existingSeed == null) { // Prime the image seed = imageManager.PrimeSeed(seed); // Save the image seed = repository.Save(seed); } else { seed = existingSeed; } var response = Request.CreateResponse(HttpStatusCode.Created, new SeedModel { id = seed.Id, image = "data:image/jpg;base64," + Convert.ToBase64String(seed.ImageData, 0, seed.ImageData.Length) }); response.Headers.Location = new Uri(Request.RequestUri, "/api/seed/" + seed.Id); return(response); }
public void init(Controller c, float startX, float startY, float destX, float destY, int coordX) { this.transform.position = new Vector3(startX, startY, 0); this.c = c; this.destX = destX; this.destY = destY; this.coordX = coordX; c.inControl = false; var seedObject = GameObject.CreatePrimitive(PrimitiveType.Quad); seed = seedObject.AddComponent <SeedModel> (); seed.init(this); saplingHeight = 0f; branchColor = c.branchColors[c.colorsArrayIndex]; leafColor = c.leafColors [c.colorsArrayIndex]; rootColor = c.rootColors [c.colorsArrayIndex]; c.colorsArrayIndex = (c.colorsArrayIndex + 1) % c.branchColors.Count; }
public ActionResult CreateUpdateSeed(Int32 id) { var seedModel = new SeedModel(); seedModel.SeedGuid = Guid.NewGuid().ToString(); seedModel.DatePurchase = DateTime.Now; if (id > 0) { var seed = FarmManagementEntities.Seeds.Single(x => x.Id == id); seedModel = seed.ToType <Seed, SeedModel>(); seedModel.SeedQuality = Convert.ToInt32(seed.Quality.ParseEnum <Quality>()); seedModel.SeedQuantity = Convert.ToInt32(seed.Quantity.ParseEnum <Quantity>()); GetUploadFile(FileUploadPath.Seed, seed.Id, seed.PaymentBill); seedModel.SeedGuid = seed.Id.ToString(); } return(PartialView("SeedPartial", seedModel)); }