Beispiel #1
0
 public ActionResult Register(AgileCrmModel model)
 {
     ModelState.Remove("Id");
     if (ModelState.IsValid)
     {
         using (var ctx = new SynergyDbContext())
         {
             string ApiName = ApiTypes.AgileCrm.ToString();
             var    api     = ctx.Synergy_API.Where(x => x.Api == ApiName).FirstOrDefault();
             Synergy_ApiConfiguration configuration = new Synergy_ApiConfiguration()
             {
                 ApiId    = api.Id,
                 Email    = model.Email,
                 Key      = model.Key,
                 Url      = model.Url,
                 UserId   = Convert.ToInt32(User.Identity.Name),
                 IsActive = true
             };
             ctx.Synergy_ApiConfigurations.Add(configuration);
             ctx.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
 public void OnAuthorization(AuthorizationContext filterContext)
 {
     if (HttpContext.Current.User != null &&
         HttpContext.Current.User.Identity.IsAuthenticated)
     {
         if (!string.IsNullOrEmpty(Role))
         {
             using (var context = new SynergyDbContext())
             {
                 if (!context.Synergy_Users.Any(x => x.UserRole.ToLower() == Role.ToLower()))
                 {
                     throw new UnauthorizedAccessException("Don't have to permission to access this page.");
                 }
             }
         }
     }
     else
     {
         filterContext.Result = new RedirectToRouteResult(
             new RouteValueDictionary
         {
             { "controller", "Account" },
             { "action", "Login" }
         });
     }
 }
Beispiel #3
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     using (var ctx = new SynergyDbContext())
     {
         var configuration = ctx.Synergy_ApiConfigurations.
                             Where(x => x.Id == id && x.IsActive).FirstOrDefault();
         if (configuration != null)
         {
             configuration.IsActive = false;
         }
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Beispiel #4
0
        public ActionResult Update(int id)
        {
            AgileCrmModel model = null;

            using (var ctx = new SynergyDbContext())
            {
                model = ctx.Synergy_ApiConfigurations.
                        Where(x => x.Id == id && x.IsActive).
                        Select(x => new AgileCrmModel()
                {
                    Id    = x.Id,
                    Key   = x.Key,
                    Url   = x.Url,
                    Email = x.Email
                }).FirstOrDefault();
            }
            return(View(model));
        }
Beispiel #5
0
 public ActionResult Update(AgileCrmModel model)
 {
     if (ModelState.IsValid)
     {
         using (var ctx = new SynergyDbContext())
         {
             var configuration = ctx.Synergy_ApiConfigurations.
                                 Where(x => x.Id == model.Id && x.IsActive).FirstOrDefault();
             if (configuration != null)
             {
                 configuration.Key   = model.Key;
                 configuration.Email = model.Email;
                 configuration.Url   = model.Url;
             }
             ctx.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Beispiel #6
0
        public void AgileCrmInit(ref ContactApi contactApi, ref DealApi dealApi)
        {
            using (var ctx = new SynergyDbContext())
            {
                var userId = SynergySecurity.GetCurrentUser();

                var apiConfiguration = ctx.Synergy_ApiConfigurations.
                                       Where(x => x.UserId == userId && x.IsActive).FirstOrDefault();
                if (apiConfiguration != null)
                {
                    contactApi = new ContactApi(agileKey: apiConfiguration.Key, agileEmail: apiConfiguration.Email, agileUrl: apiConfiguration.Url);
                    dealApi    = new DealApi(agileKey: apiConfiguration.Key, agileEmail: apiConfiguration.Email, agileUrl: apiConfiguration.Url);
                }
                else
                {
                    contactApi = new ContactApi();
                    dealApi    = new DealApi();
                }
            }
        }
Beispiel #7
0
        public ActionResult Configurations()
        {
            List <AgileCrmModel> model = null;

            using (var ctx = new SynergyDbContext())
            {
                string ApiName = ApiTypes.AgileCrm.ToString();
                var    api     = ctx.Synergy_API.Where(x => x.Api == ApiName).FirstOrDefault();

                model = ctx.Synergy_ApiConfigurations.
                        Where(x => x.IsActive && x.ApiId == api.Id).
                        Select(x => new AgileCrmModel()
                {
                    Id    = x.Id,
                    Key   = x.Key,
                    Url   = x.Url,
                    Email = x.Email
                }).ToList();
            }
            return(View(model));
        }
 public HubSpotController()
 {
     context = new SynergyDbContext();
 }
Beispiel #9
0
 public InfusionSoftController()
 {
     context = new SynergyDbContext();
 }