Exemplo n.º 1
0
        public async Task <OSModel> GetOS([FromUri] int osId)
        {
            Entities.OperatingSystem os = await this._osManager.GetOS(osId);

            OSModel model = Mapper.Map <OSModel>(os);

            return(model);
        }
Exemplo n.º 2
0
 public Task <Entities.OperatingSystem> GetOS(int osId)
 {
     return(Task.Run(() =>
     {
         using (var ctx = new TLEntities())
         {
             Entities.OperatingSystem os = ctx.OperatingSystems
                                           .Where(o => o.Id == osId)
                                           .FirstOrDefault();
             if (os == null)
             {
                 throw new TLNotFoundException("os");
             }
             return os;
         }
     }));
 }
Exemplo n.º 3
0
        public Task <Tool> AddTool(ToolSubmitModel tool)
        {
            return(Task.Run(() =>
            {
                using (var ctx = new TLEntities())
                {
                    Tool toolEntity = new Tool();
                    if (tool == null)
                    {
                        throw new ArgumentException("Model is empty");
                    }
                    if (string.IsNullOrEmpty(tool.Name))
                    {
                        throw new ArgumentException("Name is empty");
                    }
                    if (string.IsNullOrEmpty(tool.SiteUrl))
                    {
                        throw new ArgumentException("Site URL is empty");
                    }
                    if (string.IsNullOrEmpty(tool.Description))
                    {
                        throw new ArgumentException("Description is empty");
                    }
                    if (tool.Type == 0)
                    {
                        throw new ArgumentException("Type is empty");
                    }
                    if (tool.License == 0)
                    {
                        throw new ArgumentException("License is empty");
                    }
                    if (string.IsNullOrEmpty(tool.Creator))
                    {
                        throw new ArgumentException("Creator is empty");
                    }
                    if (string.IsNullOrEmpty(tool.CreatorSite))
                    {
                        throw new ArgumentException("Creator site is empty");
                    }
                    Category category = ctx.Categories.Where(c => c.Id == tool.Category).FirstOrDefault();
                    if (category == null)
                    {
                        throw new ArgumentException("Category is empty");
                    }

                    toolEntity.Name = tool.Name;
                    toolEntity.ImageUrl = tool.ImageUrl;
                    toolEntity.License = (License)tool.License;
                    toolEntity.SiteUrl = tool.SiteUrl;
                    toolEntity.Type = (ToolType)tool.Type;
                    toolEntity.Updated = DateTime.MinValue;
                    toolEntity.Created = DateTime.Now;
                    toolEntity.Activated = false;
                    toolEntity.ActivationCode = Guid.NewGuid().ToString();
                    toolEntity.Category = category;
                    toolEntity.Creator = tool.Creator;
                    toolEntity.CreatorSite = tool.CreatorSite;
                    toolEntity.Description = tool.Description;
                    toolEntity.DownloadUrl = tool.DownloadUrl;
                    toolEntity.Version = tool.Version;

                    List <Entities.OperatingSystem> oss = new List <Entities.OperatingSystem>();
                    if (tool.OSs != null)
                    {
                        foreach (int osId in tool.OSs)
                        {
                            Entities.OperatingSystem os = ctx.OperatingSystems.Where(o => o.Id == osId).FirstOrDefault();
                            if (os == null)
                            {
                                throw new ArgumentException("OS doesn't exist");
                            }
                            oss.Add(os);
                        }
                    }
                    toolEntity.OperatingSystems = oss;

                    ctx.Tools.Add(toolEntity);
                    ctx.SaveChanges();
                    return toolEntity;
                }
            }));
        }