public async Task <TimeSheet> AddTimeSheet(string userId, string data)
        {
            ApplicationUser user = await userManager.FindByIdAsync(userId);

            ApplicationUser werkgever = await userManager.FindByIdAsync(user.WerkgeverID);

            Console.WriteLine(userId);
            TimeSheet _timeSheet = new TimeSheet();

            _timeSheet.Id           = userId;
            _timeSheet.Month        = DateTime.Now.ToString("MMMM");
            _timeSheet.ProjectHours = 0;
            _timeSheet.Overwork     = 0;
            _timeSheet.Sick         = 0;
            _timeSheet.Training     = 0;
            _timeSheet.Other        = 0;
            _timeSheet.Project      = werkgever.Lastname;
            _timeSheet.Submitted    = false;
            _timeSheet.Approved     = "Not submitted";
            _timeSheet.Data         = data;
            _timeSheet.Url          = Guid.NewGuid().ToString();
            _timeSheet.Comment      = "";
            _timeSheet.theDate      = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);


            var result = context.Add(_timeSheet);

            context.SaveChanges();


            return(_timeSheet);
        }
Esempio n. 2
0
        public IActionResult Post([FromForm] Entry entry)
        {
            _context.Add(entry);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Home", new { lat = entry.Lat, lng = entry.Lng }));
        }
        public int AddCustomer(RequestModel <Model.Master.CustomerModel> input)
        {
            //Initializing the Object
            CustomerModelDB customerModelDB = new CustomerModelDB

            {
                CustomerId    = input.RequestParameter.CustomerId,
                Name          = input.RequestParameter.Name,
                Code          = input.RequestParameter.Code,
                SubDomain     = input.RequestParameter.SubDomain,
                Description   = input.RequestParameter.Description,
                Active        = CommonConstants.ActiveStatus,
                ContactNumber = input.RequestParameter.ContactNumber,
                Address       = input.RequestParameter.Address,
                OtherInfo     = input.RequestParameter.OtherInfo,
                CreatedDate   = DateTime.Now,
                CreatedBy     = input.RequestParameter.CreatedBy
            };

            //Saving in database
            RepositoryContext.Add(customerModelDB);
            this.RepositoryContext.SaveChanges();
            input.RequestParameter.CustomerId = customerModelDB.CustomerId;
            return(customerModelDB.CustomerId);
        }
Esempio n. 4
0
        public async Task <Cost> AddCost(Cost cost)
        {
            if (cost == null)
            {
                throw new ArgumentNullException(nameof(cost));
            }

            repository.Add(cost);
            await repository.SaveChangesAsync();

            return(await repository.Cost
                   .Include(c => c.CostCategory)
                   .Include(c => c.PayType)
                   .Include(c => c.Store)
                   .FirstOrDefaultAsync(c => c.Id == cost.Id));
        }
        public async Task <IActionResult> Create([Bind("ID,FullName,Age,DOJ,FileName")] Employee employee, IFormFile fileName)
        {
            if (ModelState.IsValid)
            {
                string path     = Environment.CurrentDirectory;
                string fullName = Path.Combine(path, "wwwroot", "Images", fileName.filename);

                employee.fileName = fullName;
                _context.Add(employee);

                await _context.SaveChangesAsync();

                // upload file
                if (FileName.Length > 0)
                {
                    using (var stream = System.IO.File.Create(fullName))
                    {
                        await FileName.CopyToAsync(stream);
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Esempio n. 6
0
 /// <summary>
 /// 添加单个实体数据
 /// </summary>
 /// <param name="entity">实体对象</param>
 public void AddSingle(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     RepositoryContext.Add(entity);
     RepositoryContext.SaveChanges();
 }
        public async Task <IActionResult> Create([Bind("Id,Username,Password,RegistrationDate,Forename,Surname,Address1,Address2,Address3,Address4,PostCode,Email,HomePhone,MobilePhone,ConfirmPassword")] RegisteredUser registeredUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(registeredUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(registeredUser));
        }
        public async Task <IActionResult> Create([Bind("ID,FullName,Age,DOJ,FileName")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Esempio n. 9
0
        public async Task <IActionResult> Create([Bind("ProductId,Name")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
        public async Task <IActionResult> Create([Bind("CustomerId,Name")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public async Task <IActionResult> Create([Bind("ArtistID,ArtistName")] Artist artist)
        {
            if (ModelState.IsValid)
            {
                artist.ArtistID = Guid.NewGuid();
                _context.Add(artist);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(artist));
        }
Esempio n. 12
0
 public void AddMany(IEnumerable <T> source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     foreach (var item in source)
     {
         RepositoryContext.Add(item);
     }
     RepositoryContext.SaveChanges();
 }
        public async Task <IActionResult> Create([Bind("Id,Name,DateOfBirth,GenderId,Address,PhoneNumber,Email,Notes")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenderId"] = new SelectList(genderItems, "Id", "GenderName", customer.GenderId);
            return(View(customer));
        }
        public async Task <IActionResult> Create([Bind("OrderId,Date,OrderState,CustomerId")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "Name", order.CustomerId);
            return(View(order));
        }
        public async Task <IActionResult> Create([Bind("Id,FromDate,ToDate,NoPeople,Name,Email,Phone,Confirmed, DepositPaid, DepositPaidAmount, InvoiceTotal, FullyPaid, BookingStatus, DepositDueDate, FullyPaidDueDate")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                booking.BookingRequestDate     = DateTime.Now;
                booking.BookingLastAmendedDate = DateTime.Now;
                _context.Add(booking);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(booking));
        }
Esempio n. 16
0
        public async Task <IActionResult> Create([Bind("SongID,SongName,ArtistID")] Song song)
        {
            if (ModelState.IsValid)
            {
                song.SongID = Guid.NewGuid();
                _context.Add(song);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ArtistID"] = new SelectList(_context.Artists, "ArtistID", "ArtistName", song.ArtistID);
            return(View(song));
        }
 public Boolean StallProductCategories(List <int> Category, int StallId)
 {
     Category.ForEach(a =>
     {
         var StallProductCategories = new StallProductCategories
         {
             StallRegistrationId = StallId,
             Category            = a,
         };
         _repositoryContext.Add(StallProductCategories);
         _repositoryContext.SaveChanges();
     });
     return(true);
 }
Esempio n. 18
0
        public async Task <UserDto> Create(UserCreateDto input)
        {
            var entity = new AppUser
            {
                FirstName = input.FirstName,
                LastName  = input.LastName,
                Age       = input.Age,
                Created   = _timeService.GetUtcNow(),
                RoleId    = (int)RoleEnum.User
            };

            _db.Add(entity);
            await _db.SaveChangesAsync();

            return(entity.ToDto());
        }
 public StallRegistration StallRegistration(int UserId, int StallId)
 {
     try
     {
         var stallregistration = new StallRegistration
         {
             UserId      = UserId,
             StallId     = StallId,
             IsApproved  = false,
             IsRejected  = false,
             CreatedDate = DateTime.UtcNow
         };
         _repositoryContext.Add(stallregistration);
         _repositoryContext.SaveChanges();
         return(stallregistration);
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 20
0
        public int AddUserRole(RequestModel <UserRoleModel> input)
        {
            //Make db object
            UserRoleDB userRoleDB = new UserRoleDB
            {
                CreatedBy   = input.RequestParameter.UserId,
                CreatedDate = DateTime.Now,
                Active      = CommonConstants.ActiveStatus,
                CustomerId  = input.CustomerId.GetValueOrDefault(),
                Name        = input.RequestParameter.Name,
                Description = input.RequestParameter.Description
            };

            //Save in database
            RepositoryContext.Add(userRoleDB);
            this.RepositoryContext.SaveChanges();

            input.RequestParameter.Id = userRoleDB.Id;

            return(userRoleDB.Id);
        }
        public int AddCustomerBranch(RequestModel <CustomerBranchModel> input)
        {
            //Make db object
            CustomerBranchesDB customerBranchDB = new CustomerBranchesDB
            {
                CreatedBy     = input.RequestParameter.UserId,
                CreatedDate   = DateTime.Now,
                Active        = CommonConstants.ActiveStatus,
                CustomerId    = input.CustomerId.GetValueOrDefault(),
                Name          = input.RequestParameter.Name,
                Address       = input.RequestParameter.Address,
                Code          = input.RequestParameter.Code,
                ContactNumber = input.RequestParameter.ContactNumber,
                OtherInfo     = input.RequestParameter.OtherInfo
            };

            //Save in database
            RepositoryContext.Add(customerBranchDB);
            this.RepositoryContext.SaveChanges();

            input.RequestParameter.Id = customerBranchDB.Id;

            return(customerBranchDB.Id);
        }
Esempio n. 22
0
        public int EditRoutine(int routineId, DtoEditRoutine newRoutine, int userId)
        {
            var routineExists = _context.Routines
                                .Where(o => o.UserId == userId)
                                .Any(o => o.Id == routineId);

            if (!routineExists)
            {
                throw new NotFoundException();
            }

            var newDate = newRoutine.RoutineDate.AddDays(1);
            var note    = _context.Notes
                          .Where(o => o.Date >= newRoutine.RoutineDate)
                          .Where(o => o.Date < newDate)
                          .FirstOrDefault(o => o.RoutineId == routineId);

            if (note != null)
            {
                note.Text = newRoutine.Note;
            }
            else
            {
                var newNote = new Note();
                newNote.Text      = newRoutine.Note;
                newNote.Date      = newRoutine.RoutineDate;
                newNote.RoutineId = routineId;
                _context.Add(newNote);
            }

            var indicators = _context.Indicators
                             .Where(o => o.RoutineId == routineId)
                             .Where(o => o.Date >= newRoutine.RoutineDate)
                             .Where(o => o.Date < newDate)
                             .ToList();

            var oldWater = indicators
                           .FirstOrDefault(o => o.IndicatorTypeId == 1);

            if (oldWater != null)
            {
                oldWater.Value = newRoutine.Water;
            }
            else
            {
                var waterIndicator = new Indicator();
                waterIndicator.Date            = newRoutine.RoutineDate;
                waterIndicator.Value           = newRoutine.Water;
                waterIndicator.IndicatorTypeId = 1;
                waterIndicator.RoutineId       = routineId;
                _context.Add(waterIndicator);
            }

            var oldStress = indicators
                            .FirstOrDefault(o => o.IndicatorTypeId == 2);

            if (oldStress != null)
            {
                oldStress.Value = newRoutine.Stress switch
                {
                    "bad" => 3,
                    "normal" => 2,
                    _ => 1
                };
            }
            else
            {
                var stressIndicator = new Indicator();
                stressIndicator.RoutineId = routineId;
                stressIndicator.Date      = newRoutine.RoutineDate;
                stressIndicator.Value     = newRoutine.Stress switch
                {
                    "bad" => 3,
                    "normal" => 2,
                    _ => 1
                };
                stressIndicator.IndicatorTypeId = 2;
                _context.Add(stressIndicator);
            }

            var oldSleeping = indicators
                              .FirstOrDefault(o => o.IndicatorTypeId == 3);


            var x        = newRoutine.WakeUp - newRoutine.GoToSleep;
            var sleeping = x?.TotalHours != null ? (float)x.Value.TotalHours : 0;

            if (oldSleeping != null)
            {
                oldSleeping.Value = sleeping;
            }
            else
            {
                var sleepingIndicator = new Indicator();
                sleepingIndicator.RoutineId       = routineId;
                sleepingIndicator.Date            = newRoutine.RoutineDate;
                sleepingIndicator.Value           = sleeping;
                sleepingIndicator.IndicatorTypeId = 3;
                _context.Add(sleepingIndicator);
            }

            EditProduct(newRoutine.Cleanser, 1, routineId);
            EditProduct(newRoutine.Treatment, 2, routineId);
            EditProduct(newRoutine.Moisturizer, 3, routineId);
            EditProduct(newRoutine.SunScreen, 4, routineId);
            EditProduct(newRoutine.Other, 5, routineId);
            _context.SaveChanges();

            return(routineId);
        }
    }
Esempio n. 23
0
 public void Create(T entity)
 {
     _context.Add(entity);
     Save();
 }
Esempio n. 24
0
 public AppUsers Register(AppUsers appUsers)
 {
     _repositoryContext.Add(appUsers);
     _repositoryContext.SaveChanges();
     return(appUsers);
 }