/// <summary>
        /// Returns the lessons of a day to display.
        /// </summary>
        /// <param name="dayId">The day identifier.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The lessons of a day.</returns>
        public List <LessonDisplayDto> GetLessonsOfDayToDisplay(Guid dayId, Guid accountId)
        {
            List <LessonDisplayDto> data = new List <LessonDisplayDto>();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                IQueryable <LessonEntity> entities = ctx.LessonSet.Where(f => f.DayId == dayId && f.AccountId == accountId);
                foreach (LessonEntity entity in entities)
                {
                    LessonDisplayDto item = new LessonDisplayDto();
                    item.Id             = entity.Id;
                    item.DayId          = entity.DayId;
                    item.DayCaption     = entity.DayNavProp.Caption;
                    item.FromDate       = DateTimeHelper.DateTimeToString(entity.FromDate);
                    item.ToDate         = DateTimeHelper.DateTimeToString(entity.ToDate);
                    item.SubjectCode    = entity.SubjectNavProp.Code;
                    item.SubjectCaption = entity.SubjectNavProp.Caption;
                    item.TeacherCode    = entity.TeacherNavProp.Code;
                    item.TeacherCaption = entity.TeacherNavProp.Caption;
                    item.RoomCode       = entity.RoomNavProp.Code;
                    item.RoomCaption    = entity.RoomNavProp.Caption;
                    item.Remark         = entity.Remark;

                    data.Add(item);
                }
            }

            return(data);
        }
        /// <summary>
        /// Updates a teacher.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto UpdateTeacher(TeacherEditDto itemToSave, Guid?accountId)
        {
            ResultDto result = new ResultDto();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                TeacherEntity entity = ctx.TeacherSet.FirstOrDefault(f => f.Id == itemToSave.Id);
                if (entity == null)
                {
                    result.Error = "ERR-TEACHER-NOT-EXISTS";
                    return(result);
                }

                if (entity.AccountId == null || entity.AccountId != accountId)
                {
                    result.Error = "ERR-TEACHER-ACCOUNT-INVALID";
                    return(result);
                }

                entity.Code    = itemToSave.Code.Length > 10 ? itemToSave.Code.Substring(0, 9) : itemToSave.Code;
                entity.Caption = itemToSave.Caption.Length > 50 ? itemToSave.Caption.Substring(0, 49) : itemToSave.Caption;
                entity.ModDate = DateTime.Now;
                entity.ModUser = Environment.UserName;

                ctx.SaveChanges();
                result.Success = true;
            }

            return(result);
        }
        /// <summary>
        /// Deletes a lesson.
        /// </summary>
        /// <param name="id">The lesson identifier.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto DeleteLesson(Guid id, Guid accountId)
        {
            ResultDto result = new ResultDto();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                LessonEntity entity = ctx.LessonSet.FirstOrDefault(f => f.Id == id);
                if (entity == null)
                {
                    result.Error = "ERR-LESSON-NOT-EXISTS";
                    return(result);
                }

                if (entity.AccountId != accountId)
                {
                    result.Error = "ERR-LESSON-ACCOUNT-INVALID";
                    return(result);
                }

                ctx.LessonSet.Remove(entity);
                ctx.SaveChanges();
                result.Success = true;
                return(result);
            }
        }
Example #4
0
        /// <summary>
        /// Inserts a room.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto InsertRoom(RoomEditDto itemToSave, Guid?accountId)
        {
            ResultDto result = new ResultDto();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                RoomEntity entity = ctx.RoomSet.FirstOrDefault(f => f.Id == itemToSave.Id);
                if (entity != null)
                {
                    result.Error = "ERR-ROOM-ALREADY-EXISTS";
                    return(result);
                }

                entity           = new RoomEntity();
                entity.Id        = itemToSave.Id;
                entity.AccountId = accountId;
                entity.Code      = itemToSave.Code.Length > 10 ? itemToSave.Code.Substring(0, 9) : itemToSave.Code;
                entity.Caption   = itemToSave.Caption.Length > 50 ? itemToSave.Caption.Substring(0, 49) : itemToSave.Caption;
                entity.ModDate   = DateTime.Now;
                entity.ModUser   = Environment.UserName;
                ctx.RoomSet.Add(entity);

                ctx.SaveChanges();
                result.Success = true;
            }

            return(result);
        }
        /// <summary>
        /// Updates a lesson.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto UpdateLesson(LessonEditDto itemToSave, Guid accountId)
        {
            ResultDto result = new ResultDto();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                LessonEntity entity = ctx.LessonSet.FirstOrDefault(f => f.Id == itemToSave.Id);
                if (entity == null)
                {
                    result.Error = "ERR-LESSON-NOT-EXISTS";
                    return(result);
                }

                if (entity.AccountId != accountId)
                {
                    result.Error = "ERR-LESSON-ACCOUNT-INVALID";
                    return(result);
                }

                entity.DayId     = itemToSave.DayId;
                entity.FromDate  = DateTimeHelper.StringToDateTime(itemToSave.FromDate);
                entity.ToDate    = DateTimeHelper.StringToDateTime(itemToSave.ToDate);
                entity.SubjectId = itemToSave.SubjectId;
                entity.TeacherId = itemToSave.TeacherId;
                entity.RoomId    = itemToSave.RoomId;
                entity.Remark    = itemToSave.Remark;
                entity.ModDate   = DateTime.Now;
                entity.ModUser   = Environment.UserName;

                ctx.SaveChanges();
                result.Success = true;
                return(result);
            }
        }
        /// <summary>
        /// Inserts or updates a lesson.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto InsertUpdateLesson(LessonEditDto itemToSave, Guid accountId)
        {
            ResultDto result = new ResultDto();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                LessonEntity entity = ctx.LessonSet.FirstOrDefault(f => f.Id == itemToSave.Id);
                if (entity != null)
                {
                    result.Error = "ERR-LESSON-ALREADY-EXISTS";
                    return(result);
                }

                if (!new DayServerService().DayExists(itemToSave.DayId, ctx))
                {
                    result.Error = "ERR-LESSON-DAY-NOT-EXISTS";
                    return(result);
                }

                if (!new SubjectServerService().SubjectExists(itemToSave.SubjectId, ctx))
                {
                    result.Error = "ERR-LESSON-SUBJECT-NOT-EXISTS";
                    return(result);
                }

                if (itemToSave.TeacherId.HasValue && !new TeacherServerService().TeacherExists(itemToSave.TeacherId.Value, ctx))
                {
                    result.Error = "ERR-LESSON-TEACHER-NOT-EXISTS";
                    return(result);
                }

                if (itemToSave.RoomId.HasValue && !new RoomServerService().RoomExists(itemToSave.RoomId.Value, ctx))
                {
                    result.Error = "ERR-LESSON-ROOM-NOT-EXISTS";
                    return(result);
                }

                entity           = new LessonEntity();
                entity.Id        = itemToSave.Id;
                entity.AccountId = accountId;
                entity.DayId     = itemToSave.DayId;
                entity.FromDate  = DateTimeHelper.StringToDateTime(itemToSave.FromDate);
                entity.ToDate    = DateTimeHelper.StringToDateTime(itemToSave.ToDate);
                entity.SubjectId = itemToSave.SubjectId;
                entity.TeacherId = itemToSave.TeacherId;
                entity.RoomId    = itemToSave.RoomId;
                entity.Remark    = itemToSave.Remark;
                entity.ModDate   = DateTime.Now;
                entity.ModUser   = Environment.UserName;
                ctx.LessonSet.Add(entity);

                ctx.SaveChanges();
                result.Success = true;
                return(result);
            }
        }
Example #7
0
 /// <summary>
 /// Returns the day lookup.
 /// </summary>
 /// <returns>The day lookup.</returns>
 public List <DayLookupDto> GetDayLookup()
 {
     using (BzsEntityContainer ctx = this.CreateContainer())
     {
         return(ctx.DaySet.Select(f => new DayLookupDto
         {
             Id = f.Id,
             Order = f.Order,
             Code = f.Code,
             Caption = f.Caption
         }).ToList());
     }
 }
Example #8
0
        /// <summary>
        /// Returns the account identifier.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <returns>The account identifier.</returns>
        public Guid GetAccountId(string account)
        {
            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                AccountEntity entity = ctx.AccountSet.FirstOrDefault(f => f.Account == account);
                if (entity != null)
                {
                    return(entity.Id);
                }
            }

            return(Guid.Empty);
        }
Example #9
0
        /// <summary>
        /// Returns the login result.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <param name="password">The password.</param>
        /// <returns>The login result.</returns>
        public LoginResultDto Login(string account, string password)
        {
            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                AccountEntity accountEntity = ctx.AccountSet.FirstOrDefault(f => f.Account == account && f.Password == password);
                if (accountEntity != null)
                {
                    return(new LoginResultDto(Guid.NewGuid()));
                }

                return(new LoginResultDto());
            }
        }
        /// <summary>
        /// Returns the lesson.
        /// </summary>
        /// <param name="id">The lesson identifier.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The lesson data.</returns>
        public LessonEditDto GetLesson(Guid id, Guid accountId)
        {
            LessonEditDto data = null;

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                LessonEntity entity = ctx.LessonSet.FirstOrDefault(f => f.Id == id && f.AccountId == accountId);
                if (entity != null)
                {
                    data = this.FillLessonEditDto(new LessonEditDto(), entity);
                }
            }

            return(data);
        }
        /// <summary>
        /// Returns the lessons of a day.
        /// </summary>
        /// <param name="dayId">The day identifier.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The lessons of the day.</returns>
        public List <LessonEditDto> GetLessonsOfDay(Guid dayId, Guid accountId)
        {
            List <LessonEditDto> data = new List <LessonEditDto>();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                IQueryable <LessonEntity> entities = ctx.LessonSet.Where(f => f.DayId == dayId && f.AccountId == accountId);
                foreach (LessonEntity entity in entities)
                {
                    LessonEditDto item = this.FillLessonEditDto(new LessonEditDto(), entity);
                    data.Add(item);
                }
            }

            return(data);
        }
        /// <summary>
        /// Returns the teacher lookup data.
        /// </summary>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The teacher lookup data.</returns>
        public List <TeacherLookupDto> GetTeacherLookup(Guid accountId)
        {
            List <TeacherLookupDto> data;

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                data = ctx.TeacherSet.Where(f => f.AccountId == null || f.AccountId == accountId).Select(f => new TeacherLookupDto
                {
                    Id      = f.Id,
                    Code    = f.Code,
                    Caption = f.Caption
                }).ToList();
            }

            return(data);
        }
        /// <summary>
        /// Deletes a teacher.
        /// </summary>
        /// <param name="id">The teacher identifier.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto DeleteTeacher(Guid id, Guid accountId)
        {
            ResultDto result = new ResultDto();

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                TeacherEntity entity = ctx.TeacherSet.FirstOrDefault(f => f.Id == id);
                if (entity == null)
                {
                    result.Error = "ERR-TEACHER-NOT-EXISTS";
                    return(result);
                }

                if (entity.AccountId == null)
                {
                    result.Error = "ERR-TEACHER-ACCOUNT-INDEPENDENT";
                    return(result);
                }

                if (entity.AccountId != accountId)
                {
                    result.Error = "ERR-TEACHER-ACCOUNT-INVALID";
                    return(result);
                }

                if (entity.LessonNavProp.Any())
                {
                    result.Error = "ERR-TEACHER-USED";
                    return(result);
                }

                ctx.TeacherSet.Remove(entity);
                ctx.SaveChanges();
                result.Success = true;
                return(result);
            }
        }
Example #14
0
        /// <summary>
        /// Registers the data.
        /// </summary>
        /// <param name="data">The data to register.</param>
        /// <returns>The result.</returns>
        public ResultDto Register(RegisterDto data)
        {
            if (data == null)
            {
                return(new ResultDto("No data provided."));
            }

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                if (ctx.AccountSet.Count(f => f.Account == data.Account) > 0)
                {
                    return(new ResultDto("The account already exists."));
                }

                if (data.Account.Length > 50)
                {
                    return(new ResultDto("ERR-REG-ACCOUNT-LENGTH"));
                }

                if (data.Password.Length > 50)
                {
                    return(new ResultDto("ERR-REG-PASSWORD-LENGTH"));
                }

                AccountEntity entity = new AccountEntity();
                entity.Id       = Guid.NewGuid();
                entity.Account  = data.Account;
                entity.Password = data.Password;
                entity.Email    = data.Email;
                entity.ModDate  = DateTime.Now;
                entity.ModUser  = Environment.UserName;

                ctx.AccountSet.Add(entity);
                ctx.SaveChanges();
                return(new ResultDto(true));
            }
        }
 /// <summary>
 /// Returns a value indicating whether the teacher exists.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="ctx">The entity container.</param>
 /// <returns>The teacher exists.</returns>
 public bool TeacherExists(Guid id, BzsEntityContainer ctx)
 {
     return(ctx.TeacherSet.Any(f => f.Id == id));
 }
Example #16
0
 /// <summary>
 /// Returns a value indicating whether the day exists.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="ctx">The entity container.</param>
 /// <returns>The day exists.</returns>
 public bool DayExists(Guid id, BzsEntityContainer ctx)
 {
     return(ctx.DaySet.Any(f => f.Id == id));
 }
Example #17
0
 /// <summary>
 /// Returns a value indicating whether the room exists.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="ctx">The entity container.</param>
 /// <returns>The room exists.</returns>
 public bool RoomExists(Guid id, BzsEntityContainer ctx)
 {
     return(ctx.RoomSet.Any(f => f.Id == id));
 }
Example #18
0
        /// <summary>
        /// Retrieves the credentials.
        /// </summary>
        /// <param name="email">The email address.</param>
        public void RetrieveCredentials(string email)
        {
            if (email == null)
            {
                return;
            }

            bool   sendMail = false;
            string account  = string.Empty;
            string password = string.Empty;

            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                AccountEntity accountEntity = ctx.AccountSet.FirstOrDefault(f => f.Email == email);
                if (accountEntity != null)
                {
                    sendMail = true;
                    account  = accountEntity.Account;
                    password = accountEntity.Password;
                }
            }

            if (sendMail)
            {
                string sendEmailHost     = null;
                string sendEmailAddress  = null;
                string sendEmailAccount  = null;
                string sendEmailPassword = null;
                string sendEmailDomain   = null;

                foreach (string key in ConfigurationManager.AppSettings.Keys)
                {
                    switch (key)
                    {
                    case "SendEmailHost":
                        sendEmailHost = ConfigurationManager.AppSettings[key];
                        break;

                    case "SendEmailAddress":
                        sendEmailAddress = ConfigurationManager.AppSettings[key];
                        break;

                    case "SendEmailAccount":
                        sendEmailAccount = ConfigurationManager.AppSettings[key];
                        break;

                    case "SendEmailPassword":
                        sendEmailPassword = ConfigurationManager.AppSettings[key];
                        break;

                    case "SendEmailDomain":
                        sendEmailDomain = ConfigurationManager.AppSettings[key];
                        break;
                    }
                }

                StringBuilder message = new StringBuilder();
                message.AppendLine("Someone has requested your credentials for the BZS Surselva application.");
                message.AppendLine();
                message.AppendLine("Account: " + account);
                message.AppendLine("Password: "******"Kind regards");
                message.AppendLine("BZS Surselva");
                message.AppendLine("Administrator");

                MailMessage mail   = new MailMessage(sendEmailAddress, email);
                SmtpClient  client = new SmtpClient();
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.EnableSsl             = true;
                client.Credentials           = new NetworkCredential(sendEmailAccount, sendEmailPassword, sendEmailDomain);
                client.Host  = sendEmailHost;
                mail.Subject = "BZS Surselva: Your Account";
                mail.Body    = message.ToString();
                try
                {
                    client.Send(mail);
                }
                catch (SmtpException)
                {
                }
            }
        }
Example #19
0
 /// <summary>
 /// Returns a value indicating whether the subject exists.
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="ctx">The entity container.</param>
 /// <returns>The subject exists.</returns>
 public bool SubjectExists(Guid id, BzsEntityContainer ctx)
 {
     return(ctx.SubjectSet.Any(f => f.Id == id));
 }