Ejemplo n.º 1
0
        public long CreateReport(ReportItemDto report)
        {
            if (DateTime.Parse(report.Date).Date > DateTime.Now.Date || _context.Reports.Where(x => x.UserID == report.UserID && x.Date.Date == DateTime.Parse(report.Date).Date).Any())
            {
                return(-1);
            }

            var currentReport = _context.Reports.Where(x => x.UserID == report.UserID && x.Date.Date == DateTime.Parse(report.Date).Date).SingleOrDefault();

            if (currentReport != null)
            {
                _context.Reports.Remove(currentReport);
            }

            var newReport = new Report
            {
                UserID   = report.UserID,
                Name     = report.Name,
                Surname  = report.Surname,
                Sector   = report.Sector.SectorName,
                WorkName = report.Sector.WorkName,
                Amount   = Math.Round(report.Amount, 2),
                Hours    = Math.Round(report.Hours, 2),
                Date     = DateTime.Parse(report.Date),
            };

            _context.Reports.Add(newReport);
            _context.SaveChanges();

            return(newReport.Id);
        }
Ejemplo n.º 2
0
        public bool AddSector(SectorDto sector)
        {
            var newSector = new Sector
            {
                SectorName = sector.SectorName,
                WorkName   = sector.WorkName,
            };

            if (!_context.Sectors.Any(x => (x.SectorName == sector.SectorName)))
            {
                _context.Sectors.Add(newSector);
                _context.SaveChanges();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public bool Register(RegisterDto register)
        {
            var user = new User
            {
                UserId   = register.UserID,
                Name     = register.Name,
                Surname  = register.Surname,
                Password = Hash.GetHash(register.Password)
            };

            if (!_context.Users.Any(x => (x.UserId == user.UserId)))
            {
                _context.Users.Add(user);
                _context.SaveChanges();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private void AddPlan(SectorPlanDto sector, string hours, string date)
        {
            if (sector.Workers.Any())
            {
                foreach (ShortUserDto worker in sector.Workers)
                {
                    var newPlan = new Plan
                    {
                        UserID   = worker.UserID,
                        WorkName = sector.Sector.WorkName,
                        Sector   = sector.Sector.SectorName,
                        Hours    = hours,
                        Date     = DateTime.Parse(date),
                    };

                    _context.Plans.Add(newPlan);
                    _context.SaveChanges();
                }
            }
        }
        public bool SendToAll(string message)
        {
            List <int> usersList = new List <int>();

            usersList = _context.Users.Where(x => x.UserId != 0).Select(x => x.UserId).ToList();

            foreach (int id in usersList)
            {
                var newMessage = new Message
                {
                    From        = 0, //from admin (admin has ID = 0)
                    To          = id,
                    MessageText = message,
                    Date        = DateTime.Now,
                };

                _context.Messages.Add(newMessage);
            }

            _context.SaveChanges();
            return(true);
        }