private void LoadApplication(SoftApplication app)
 {
     ltrTitle.Text = this.Title = img.AlternateText = app.Title;
     lblShortDescription.Text = app.ShortDescription;
     ltrLongDescription.Text = app.LongDescription;
     if (string.IsNullOrWhiteSpace(app.ImagePath))
     {
         img.Visible = false;
     }
     else
     {
         img.ImageUrl = Constants.ApplicationImagesFolderPath + app.ImagePath;
     }
     if (app.ApplicationDemos != null)
     {
         rptDemos.DataSource = DemoManager.GetApplicationDemos(app.ID);
         rptDemos.DataBind();
     }
     if (app.Features != null)
     {
         rptFeatures.DataSource = app.Features;
         rptFeatures.DataBind();
     }
     if (app.ApplicationDocuments != null)
     {
         rptDocuments.DataSource = DocumentManager.GetDocuments(app.ID);
         rptDocuments.DataBind();
     }
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            SoftApplication application = new SoftApplication();
            application.Title = txtTitle.Text.Trim();
            application.ShortDescription = txtShortDescription.Text.Trim();
            application.LongDescription = txtLongDescription.Content;
            application.ID = AKConvert.ToInt64(btnSave.CommandArgument);
            application.DocumentIDs = (from ListItem li in lstDocuments.Items where li.Selected select AKConvert.ToInt64(li.Value)).ToList();
            application.DemoIDs = (from ListItem li in lstDemos.Items where li.Selected select AKConvert.ToInt64(li.Value)).ToList();
            application.FeatureNames = txtFeatures.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            try
            {
                ApplicationManager.SaveApplication(application);
                if (fuImage != null && fuImage.PostedFile != null && !string.IsNullOrEmpty(fuImage.FileName))
                {
                    string file = Constants.ApplicationImagesFolderPhisicalPath + application.ID + Path.GetExtension(fuImage.FileName);

                    fuImage.SaveAs(file);
                    ApplicationManager.UpdateApplicationImagePath(application.ID, Path.GetFileName(file));
                }
                RedirectBack();
            }
            catch (Exception ex)
            {
                DisplayErrorMessage(ex.ToString());
            }
        }
Example #3
0
        public static void SaveApplication(SoftApplication app)
        {
            using (var db = CreateDataContext())
            {
                SoftApplication application = db.SoftApplications.FirstOrDefault(s => s.ID == app.ID) ?? new SoftApplication();
                application.ApplicationDemos.Clear();
                application.ApplicationDocuments.Clear();

                foreach (var feature in application.Features.ToList())
                {
                    db.Features.Remove(feature);
                }
                application.Features.Clear();
                foreach (long demoID in app.DemoIDs)
                {
                    application.ApplicationDemos.Add(new ApplicationDemo { DemoID = demoID });
                }
                foreach (long documentID in app.DocumentIDs)
                {
                    application.ApplicationDocuments.Add(new ApplicationDocument { DocumentID = documentID });
                }
                foreach (string feature in app.FeatureNames)
                {
                    application.Features.Add(new Feature {Title = feature});
                }
                application.Title = app.Title;
                application.ShortDescription = app.ShortDescription;
                application.LongDescription = app.LongDescription;
                if (application.ID == 0)
                {
                    db.SoftApplications.Add(application);
                }
                db.SaveChanges();
                app.ID = application.ID;
            }
        }