Ejemplo n.º 1
0
        /// <summary>
        /// Loads landscape from a file.
        /// </summary>
        /// <param name="file"> the file to be read.</param>
        /// <returns></returns>
        public async Task Load(StorageFile file)
        {
            if (file != null)
            {
                string xml = await FileIO.ReadTextAsync(file);

                //loading
                try {
                    LandscapeBuilder lb = new LandscapeBuilder {
                        XML = xml
                    };
                    BuilderModels.Clear();
                    foreach (string key in lb.Builders.Keys)
                    {
                        BuilderModel model = new BuilderModel(lb.Builders[key])
                        {
                            ID = key
                        };
                        BuilderModels.Add(model);
                    }
                    await Output.SetAsync("File was loaded sucessfully.");
                } catch (Exception) {
                    await Output.SetAsync("Unable to deserialize the file.");
                } finally { }
            }
            else
            {
                //cancelled
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a BuilderModel based on parameters.
        /// </summary>
        /// <param name="builderIndex"> Indesx of the selected type in PossibleBuilders.</param>
        /// <param name="typeParameterIndex">Indesx of the selected type in PossibleTypeParameters.</param>
        public void Add(int builderIndex, int typeParameterIndex)
        {
            Type builderType  = PossibleBuilders[builderIndex];
            Type specificType = builderType;

            if (builderType.IsGenericType)
            {
                specificType = builderType.MakeGenericType(new Type[] { PossibleTypeParameters[typeParameterIndex] });
            }
            BuilderModels.Add(new BuilderModel((IAlgorithmBuilder)Activator.CreateInstance(specificType)));
        }
        public async Task <ActionResult> Create(AuctionEditVM editVM, int?id, HttpPostedFileBase upload)//
        {
            var    userId  = Session["accountId"] ?? 0;
            string message = "";

            if (id == null)
            {
                Auction auction = new Auction();
                if (ModelState.IsValid) //AuctionVM
                {
                    if ((int)userId != 0)
                    {
                        await BuilderModels.CreateEntity(editVM, auction, userId, upload);

                        message = "Данные записаны!";
                    }
                    else
                    {
                        message = "Ошибка. Данные не записаны!";
                    }

                    return(new JsonResult {
                        Data = message, JsonRequestBehavior = JsonRequestBehavior.DenyGet
                    });
                }

                return(View(auction));
            }
            else
            {
                //Auction auction = await db.Auctions.FindAsync(id);
                AuctionBO auctionBO = DependencyResolver.Current.GetService <AuctionBO>();
                auctionBO = auctionBO.LoadAsNoTracking((int)id);//.Load((int)id);
                if (auctionBO == null)
                {
                    return(HttpNotFound());
                }
                message = "Данные перезаписаны!";
                BuilderModels.mapper = mapper;
                await BuilderModels.EditEntityAsync(editVM, auctionBO, userId, upload);    //

                return(new JsonResult {
                    Data = message, JsonRequestBehavior = JsonRequestBehavior.DenyGet
                });
            }
        }
Ejemplo n.º 4
0
 public void Delete(int index)
 {
     BuilderModels.Remove(BuilderModels[index]);
 }