Example #1
0
        public void UpdateSoa(Contracts.Soa.Soa soa)
        {
            var types = soa.SoaChapters.Select(c => c.SoaType).Distinct();

            if (types.Count() > 1)
            {
                throw new ArgumentException("Multiple SoA types", "SoaType");
            }
            var type = types.First();

            var user         = (ClaimsIdentity)HttpContext.Current.User.Identity;
            var companyClaim = user.Claims.FirstOrDefault(c => c.Type == ClaimTypes.PrimaryGroupSid);

            if (companyClaim != null)
            {
                var companyId = Convert.ToInt32(companyClaim.Value);
                using (var db = new RAAPEntities(GetConnectionString()))
                {
                    //Update settings
                    var settings = db.SoaSettings.FirstOrDefault(s => s.SoaType == type);
                    if (settings == null)
                    {
                        settings = new SoaSetting()
                        {
                            SoaType = type
                        };
                        db.SoaSettings.Add(settings);
                    }
                    settings.Relevant = soa.Enabled;
                    //Update existing
                    //Remove deleted
                    var dbSoas     = db.Soas.Where(s => s.SoaType == type).ToDictionary(s => s.SoaId);
                    var soasLevel3 = soa.SoaChapters.SelectMany(s => s.SubChapters).SelectMany(s => s.SubChapters).ToList();
                    UpdateSoas(soasLevel3, dbSoas, db);
                    db.Soas.RemoveRange(dbSoas.Values);
                    soa.SoaChapters.Where(s => s.SoaId > 0).ForEach(s => dbSoas[s.SoaId].UpdateFrom(s, db));
                    //Add new
                    AddNewSoas(soasLevel3, companyId, db);

                    db.SaveChanges();
                }
            }
        }
Example #2
0
 public IHttpActionResult UpdateSoa([FromBody] Contracts.Soa.Soa soa)
 {
     SoaService.UpdateSoa(soa);
     return(Ok());
 }