コード例 #1
0
        public IHttpActionResult PutStudent(string id, Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != student.CollegeID)
            {
                return(BadRequest());
            }

            db.Entry(student).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public ActionResult Register(User user)
        {
            if (Session != null && Session["AccountType"].ToString().Equals(AccountType.Admin))
            {
                if (_coreContext.Users.Count() == 6)
                {
                    return(Json(new { Message = "Maximun 5 Account are only allowed. Please contact admin" }));
                }
                var tempUser = _coreContext.Users.ToList();
                var lastUser = tempUser.LastOrDefault();
                user.AccountId   = 1;
                user.Password    = EncryptDecryptData.Encrypt(user.Password);
                user.AccountType = AccountType.TaxAccount;
                // accountId is used for session, also act as schema id
                if (lastUser != null)
                {
                    user.AccountId = lastUser.AccountId + 1;
                }

                _coreContext.Users.Add(user);
                _coreContext.SaveChanges();
                return(Json(new { Message = "Account registered successfully." }));
            }
            return(Json(new { Message = "User is not Admin." }));
        }
コード例 #3
0
        public Boolean saveManyPermissonsToProfile(List <Permissions> permissions, Profile profile)
        {
            Boolean saveSuccess = false;

            try
            {
                List <PermissonsOfProfile> prOfProfiles = new List <PermissonsOfProfile>();
                DateTime now = DateTime.Now;
                foreach (Permissions pr in permissions)
                {
                    PermissonsOfProfile prOfProf = new PermissonsOfProfile();

                    prOfProf.PermissionsId = pr.PermissionsId;
                    prOfProf.AssignmentAt  = now;
                    prOfProf.ModifiedAt    = now;
                    prOfProf.ProfileId     = profile.ProfileId;
                    prOfProfiles.Add(prOfProf);
                }
                _context.permissonsOfProfiles.AddRange(prOfProfiles);
                _context.SaveChanges();
                saveSuccess = true;
                _logger.LogInformation("[SAVE PERMISSONS] number:" + permissions.Count);
            }
            catch (DbUpdateException ex)
            {
                _logger.LogError("[NOT SAVE PERMISSON] permissons: " + permissions.Count + "\nExceprtion:\n" + ex.Message
                                 + "\n" + ex.StackTrace);
            }
            return(saveSuccess);
        }
コード例 #4
0
        public IHttpActionResult PutAttendance(int id, Attendance attendance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != attendance.ID)
            {
                return(BadRequest());
            }

            db.Entry(attendance).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AttendanceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #5
0
ファイル: SampleDbController.cs プロジェクト: pcjonkman/core
        public async Task <IActionResult> Post([FromBody] Post post)
        {
            var currentUser = await GetCurrentUserAsync();

            if (currentUser == null)
            {
                return(Json(new Array[] {}));
            }

            if (ModelState.IsValid)
            {
                if (post.User != null && post.User.Id != null)
                {
                    var selectedDbUser = _context.Users.SingleOrDefault(u => u.OwnerId == post.User.Id);
                    if (selectedDbUser != null && selectedDbUser.IsLoggedIn && checkWithCurrentUser(selectedDbUser))
                    {
                        _context.Posts.Add(new Post {
                            Id = Guid.NewGuid().ToString(), UserId = selectedDbUser.Id, Content = post.Content
                        });
                        _context.SaveChanges();
                    }
                }
            }

            return(Json(await GetUsers()));
        }
コード例 #6
0
        public void Add(TEntityDTO entity)
        {
            var mappedEntity = Mapper.Map <TEntity>(entity);

            Db.Set <TEntity>().Add(mappedEntity);
            Db.SaveChanges();
        }
コード例 #7
0
        public void PostTodo(Body todo)
        {
            var results = _context.ToDo.Add(new todo.data.ToDo()
            {
                Item       = todo.Item,
                IsComplete = false
            });

            _context.SaveChanges();
        }
コード例 #8
0
        public JsonResult Post([FromBody] Beer beer)
        {
            if (beer.BeerId != 0)
            {
                return(Json("Invalid Request"));
            }
            _coreContext.Beer.Add(beer);

            _coreContext.SaveChanges();
            return(Json(beer));
        }
コード例 #9
0
        public ActionResult Create(LessonViewModel lessonviewmodel)
        {
            if (ModelState.IsValid)
            {
                db.LessonViewModels.Add(lessonviewmodel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(lessonviewmodel));
        }
コード例 #10
0
ファイル: UsersController.cs プロジェクト: s00172004/test
        public ActionResult Create([Bind(Include = "ID,FirstName,MidName,LastName,DOB")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
コード例 #11
0
        public Referral Save(Referral referral)
        {
            Context.SaveChanges();
            var r = ReferralAcceptanceService.HandleAcceptedReferral(referral);

            if (r)
            {
                PatientSearchService.UpdateEntry(referral.GeneratedPatientID.Value);
            }
            return(referral);
        }
コード例 #12
0
 public T Create(T model)
 {
     try
     {
         _entity.Add(model);
         _context.SaveChanges();
         return(model);
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #13
0
 public DrinkType NewDrinkType(DrinkType type)
 {
     try
     {
         _context.DrinkTypes.Add(type);
         _context.SaveChanges();
         return(type);
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #14
0
 public User CreateUser(User user)
 {
     try
     {
         _context.Users.Add(user);
         _context.SaveChanges();
         return(user);
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #15
0
        public ActionResult AddReceipt([FromBody] Receipt Receipt)
        {
            _context.Receipts.Add(new Receipt
            {
                Amount   = Receipt.Amount,
                Comment  = Receipt.Comment,
                Currency = Receipt.Currency,
                Date     = Receipt.Date,
                Provider = Receipt.Provider
            });
            _context.SaveChanges();

            return(Ok());
        }
コード例 #16
0
        public bool CreateAdmin(Admin admin)
        {
            var newAdmin = CreateCrtyptoPassword(admin);

            try
            {
                _context.Admins.Add(newAdmin);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #17
0
 public StatesOfUser save(StatesOfUser statesOfUser)
 {
     try
     {
         _context.statesOfUsers.Add(statesOfUser);
         _context.SaveChanges();
         _logger.LogInformation("[SAVE STATE OF USER]");
         return(_context.statesOfUsers.Last());
     }
     catch (DbUpdateException ex)
     {
         _logger.LogError("[NOT SAVE STATE OF USER] email-user: "******"\nExceprtion:\n" + ex.Message
                          + "\n" + ex.StackTrace);
     }
     return(null);
 }
コード例 #18
0
 public HomeAddress save(HomeAddress homeAddress)
 {
     try
     {
         _context.homeAddresses.Add(homeAddress);
         _context.SaveChanges();
         _logger.LogInformation("[SAVE HOME ADDRESS]");
         return(_context.homeAddresses.Last());
     }
     catch (DbUpdateException ex)
     {
         _logger.LogError("[NOT SAVE HOME ADDRESS] num-home: " + homeAddress.NumHome + "\nExceprtion:\n" + ex.Message
                          + "\n" + ex.StackTrace);
     }
     return(null);
 }
コード例 #19
0
        public IActionResult Add(Employee employee)
        {
            context.Employees.Add(employee);
            context.SaveChanges();

            return(Ok());
        }
コード例 #20
0
        public ActionResult MenuAssign(Guid[] MenuIds, int?RoleId)
        {
            AT_RolesForMenu objRolesMenu = null;

            try
            {
                var ExistRoleMenu = (from a in CoreContext.AT_RolesForMenu where a.RoleId == RoleId select a).ToList();

                foreach (var obj in ExistRoleMenu)
                {
                    CoreContext.AT_RolesForMenu.Remove(obj);
                }

                foreach (var MenuId in MenuIds)
                {
                    objRolesMenu = new AT_RolesForMenu();

                    objRolesMenu.MenuId      = MenuId;
                    objRolesMenu.RoleId      = RoleId ?? 0;
                    objRolesMenu.CreatedDate = DateTime.Now;
                    objRolesMenu.CreatedBy   = User.Identity.Name;

                    CoreContext.AT_RolesForMenu.Add(objRolesMenu);
                }

                CoreContext.SaveChanges();

                return(Success(M("savedsucessfully")));
            }
            catch (Exception e)
            {
                //log.Error("Internal Server error", e);
                return(Error("An error occured while processing the request"));
            }
        }
コード例 #21
0
        public ActionResult Index(RolesMenuModel model)
        {
            try
            {
                AT_Roles objRoles = null;

                if (model.RoleId == null)
                {
                    objRoles             = new AT_Roles();
                    objRoles.IsVisible   = true;
                    objRoles.CreatedBy   = User.Identity.Name;
                    objRoles.CreatedDate = DateTime.Now;

                    CoreContext.AT_Roles.Add(objRoles);
                }
                else
                {
                    objRoles              = (from a in CoreContext.AT_Roles where a.RoleId == model.RoleId select a).FirstOrDefault();
                    objRoles.ModifiedBy   = User.Identity.Name;
                    objRoles.ModifiedDate = DateTime.Now;
                }

                objRoles.Name = model.RoleName;

                CoreContext.SaveChanges();

                return(Success(M("savedsucessfully")));
            }

            catch (Exception e)
            {
                return(Error("InternalError"));
            }
        }
コード例 #22
0
ファイル: RepoBase.cs プロジェクト: dieasmaz/SaleSystem
 public int SaveChanges()
 {
     try
     {
         return(Db.SaveChanges());
     }
     catch (DbUpdateConcurrencyException ex)
     {
         //A concurrency error occurred
         //Should handle intelligently
         Console.WriteLine(ex);
         throw;
     }
     catch (RetryLimitExceededException ex)
     {
         //DbResiliency retry limit exceeded
         //Should handle intelligently
         Console.WriteLine(ex);
         throw;
     }
     catch (Exception ex)
     {
         //Should handle intelligently
         Console.WriteLine(ex);
         throw;
     }
 }
コード例 #23
0
ファイル: CoreDevSeeder.cs プロジェクト: dan-gander/Violet
        public static void Seed(CoreContext context)
        {
            context.Clear <CoreUser>();

            context.Users.AddRange(new List <CoreUser>()
            {
                new CoreUser()
                {
                    Id = CoreUser.KnownUserIds.CoreAdminUser, Email = "*****@*****.**", Username = "******", Password = CryptoHelperWrapper.HashPassword("CoreDevelopment1!"), IsDeleted = false
                },
                new CoreUser()
                {
                    Id = Guid.Empty, Email = "*****@*****.**", Username = "******", Password = CryptoHelperWrapper.HashPassword("CoreDevelopment1!"), IsDeleted = false
                },
                new CoreUser()
                {
                    Id = Guid.Empty, Email = "*****@*****.**", Username = "******", Password = CryptoHelperWrapper.HashPassword("CoreDevelopment1!"), IsDeleted = false
                },
                new CoreUser()
                {
                    Id = Guid.Empty, Email = "*****@*****.**", Username = "******", Password = CryptoHelperWrapper.HashPassword("CoreDevelopment1!"), IsDeleted = false
                }
            });
            context.SaveChanges();
        }
コード例 #24
0
 public UserProfile save(UserProfile userProfile)
 {
     try
     {
         _context.userProfiles.Add(userProfile);
         _context.SaveChanges();
         _logger.LogInformation("[SAVE PROFILE OF USER]");
         return(_context.userProfiles.Last());
     }
     catch (DbUpdateException ex)
     {
         _logger.LogError("[NOT SAVE PROFILE OF USER] user-id: " + userProfile.UserAppId + "\nExceprtion:\n" + ex.Message
                          + "\n" + ex.StackTrace);
     }
     return(null);
 }
コード例 #25
0
        public static void Update(int accountId, int widgetId, Widget widget)
        {
            using (var context = new CoreContext())
            {
                Widget current = context.Widgets.Find(widgetId);
                if (current != null)
                {
                    Dashboard dashboard = context.Dashboards.Find(current.DashboardId);
                    if (dashboard.AccountId == accountId)
                    {
                        current.Alias           = widget.Alias;
                        current.MetricAlias     = widget.MetricAlias;
                        current.Type            = widget.Type;
                        current.Width           = widget.Width;
                        current.Height          = widget.Height;
                        current.BackgroundColor = widget.BackgroundColor;
                        current.TextColor       = widget.TextColor;

                        if (widget is GraphWidget)
                        {
                            GraphWidget currentGraph = (GraphWidget)current;
                            GraphWidget graph        = (GraphWidget)widget;
                            currentGraph.GraphType   = graph.GraphType;
                            currentGraph.GraphColor  = graph.GraphColor;
                            currentGraph.GraphValueX = graph.GraphValueX;
                            currentGraph.GraphValueY = graph.GraphValueY;
                        }

                        context.SaveChanges();
                    }
                }
            }
        }
コード例 #26
0
 public UserApp save(UserApp user)
 {
     try
     {
         _context.Users.Add(user);
         _context.SaveChanges();
         _logger.LogInformation("[SAVE USER]");
         return(_context.Users.Last());
     }
     catch (DbUpdateException ex)
     {
         _logger.LogError("[NOT SAVE USER] user-email: " + user.userEmail + "\nExceprtion:\n" + ex.Message
                          + "\n" + ex.StackTrace);
     }
     return(null);
 }
コード例 #27
0
        public void DeleteJobWithContent(int id)
        {
            _tracer.TraceEvent(TraceEventType.Start, 0);

            var contentRepository = new PageContentRepository(this._settings);

            using (contentRepository.AcquireLock(id))
            {
                using (var scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    Job job;
                    using (var context = new CoreContext())
                    {
                        var repository = new JobRepository(context);
                        job = repository.Load(id);
                        repository.Delete(job);
                        context.SaveChanges();
                    }

                    if (job.HasReferenceScraped)
                    {
                        contentRepository.DeleteReferenceContent(id);
                    }

                    if (job.HasTestScraped)
                    {
                        contentRepository.DeleteTestContent(id);
                    }

                    scope.Complete();
                }
            }

            _tracer.TraceEvent(TraceEventType.Stop, 0);
        }
コード例 #28
0
        public static void DeleteHours(int hoursID, CoreContext context)
        {
            var hours = context.Hours.Where(x => x.ID == hoursID || x.SSGParentID == hoursID).ToList();

            context.Hours.RemoveRange(hours);
            context.SaveChanges();
        }
コード例 #29
0
ファイル: DbService.cs プロジェクト: ItzProxy/CoreDiscordBot
        public CoreContext GetDbCoreContext()
        {
            _log = LogManager.GetCurrentClassLogger();
            var context = new CoreContext(options);

            //migration context implementation here
            if (context.Database.GetPendingMigrations().Any())
            {
                var mContext = new CoreContext(migrateOptions);
                mContext.Database.Migrate();
                mContext.SaveChanges();
                mContext.Dispose();
            }
            //sets default data and configurations are set
            //sets time before database closes
            context.Database.SetCommandTimeout(60);
            Console.Write(context.Database.IsSqlServer());
            context.EnsureSeedData();

            //connection to database
            var conn = context.Database.GetDbConnection();

            conn.Open();
            return(context);
        }
コード例 #30
0
ファイル: UsersController.cs プロジェクト: pcjonkman/core
        public async Task <IActionResult> Edit(EditViewModel model)
        {
            var currentUser = await GetCurrentUserAsync();

            if (currentUser == null)
            {
                return(View("Error"));
            }

            if (ModelState.IsValid)
            {
                var selectedDbUser = _dbContext.Users.SingleOrDefault(u => u.Id == model.User.User.Id);
                if (selectedDbUser == null)
                {
                    selectedDbUser = _dbContext.Users.Add(new User {
                        OwnerId = model.Id
                    }).Entity;
                }
                selectedDbUser.FirstName = model.User.User.FirstName;
                selectedDbUser.LastName  = model.User.User.LastName;
                _dbContext.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
コード例 #31
0
        public void CreatePersonTest()
        {
            using (var context = new CoreContext())
            {
                var person = new Person {Age = 25};
                context.Entities.Add(person);
                context.SaveChanges();

                Assert.IsTrue(person.Id > 0);

                person = context.People.FirstOrDefault(x => x.Id == person.Id);
                Assert.IsNotNull(person);
            }
        }