Exemplo n.º 1
0
 public IvhunimAndActions GetAll(bool isUserAdmin, bool isUserNextStepAdmin, bool isUserTypist, string email)
 {
     using (IvhunimEntities entities = new IvhunimEntities())
     {
         var ivhunim = new List <Ivhunim>();
         var columns = new List <RolesMainTableColumns>();
         IEnumerable <RolesActions> roles = null;
         roles = entities.RolesActionss;
         if (isUserAdmin)
         {
             roles   = roles.Where(role => role.RoleId == 1);
             ivhunim = entities.Ivhunims.ToList();
             foreach (var column in entities.RolesMainTableColumns.Where(role => role.RoleId == 1).OrderByDescending(o => o.OrderNumber))
             {
                 columns.Add(column);
             }
         }
         else if (isUserNextStepAdmin)
         {
             roles = roles.Where(role => role.RoleId == 3);
             foreach (var ivhun in entities.Ivhunims.Where(ivhun => ivhun.Institue == InstituesNames.NEXT_STEP))
             {
                 ivhunim.Add(ivhun);
             }
             foreach (var column in entities.RolesMainTableColumns.Where(role => role.RoleId == 3).OrderByDescending(o => o.OrderNumber))
             {
                 columns.Add(column);
             }
         }
         else if (isUserTypist)
         {
             roles   = roles.Where(role => role.RoleId == 4);
             ivhunim = entities.Ivhunims.ToList();
             foreach (var column in entities.RolesMainTableColumns.Where(role => role.RoleId == 4).OrderByDescending(o => o.OrderNumber))
             {
                 columns.Add(column);
             }
         }
         else
         {
             roles = roles.Where(role => role.RoleId == -1);
             foreach (var ivhun in entities.Ivhunims.Where(ivhun => ivhun.ParentEmail == email && ivhun.ReadyToBeSent == true))
             {
                 ivhunim.Add(ivhun);
             }
             foreach (var column in entities.RolesMainTableColumns.Where(role => role.RoleId == -1).OrderByDescending(o => o.OrderNumber))
             {
                 columns.Add(column);
             }
         }
         var result = new IvhunimAndActions
         {
             Ivhunim = ivhunim,
             Actions = roles.ToList(),
             Columns = columns.Select(o => o.ColumnName).ToList()
         };
         return(result);
     }
 }
Exemplo n.º 2
0
 public async Task Delete(int id)
 {
     using (IvhunimEntities entities = new IvhunimEntities())
     {
         var ivhunToDelete = entities.Ivhunims.Where(user => user.Id == id).SingleOrDefault();
         if (ivhunToDelete != null)
         {
             entities.Ivhunims.Remove(ivhunToDelete);
             await entities.SaveChangesAsync();
         }
     }
 }
Exemplo n.º 3
0
 public bool IsUserExis(int id)
 {
     using (IvhunimEntities entities = new IvhunimEntities())
     {
         var ivhun = entities.Ivhunims.Where(o => o.Id == id).SingleOrDefault();
         if (ivhun != null && entities.AspNetUsers.Any(o => o.UserName == ivhun.ParentEmail))
         {
             return(true);
         }
         return(false);
     }
 }
Exemplo n.º 4
0
 public async Task Post(Ivhunim ivhun)
 {
     try
     {
         using (IvhunimEntities entities = new IvhunimEntities())
         {
             entities.Ivhunims.Add(ivhun);
             await entities.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 5
0
 public async Task Upsert(Ivhunim ivhun)
 {
     try
     {
         using (IvhunimEntities entities = new IvhunimEntities())
         {
             entities.Entry(ivhun).State = System.Data.Entity.EntityState.Modified;
             await entities.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 6
0
 public async Task Duplicate(int id)
 {
     try
     {
         using (IvhunimEntities entities = new IvhunimEntities())
         {
             var ivhunToCopy = entities.Ivhunims.AsNoTracking().Where(user => user.Id == id).SingleOrDefault();
             if (ivhunToCopy != null)
             {
                 ivhunToCopy.FirstName = ivhunToCopy.FirstName + " - העתק";
                 entities.Ivhunims.Add(ivhunToCopy);
                 await entities.SaveChangesAsync();
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 7
0
        public IHttpActionResult EmailClient([FromUri] int id, [FromBody] RegisterBindingModel registrationModel)
        {
            try
            {
                using (IvhunimEntities entities = new IvhunimEntities())
                {
                    var ivhun = entities.Ivhunims.Where(o => o.Id == id).FirstOrDefault();
                    if (ivhun == null)
                    {
                        return(NotFound());
                    }

                    if (ivhun.ReadyToBeSent == false)
                    {
                        return(BadRequest("Cannot send ivhun not ready"));
                    }

                    string body = "";
                    if (string.IsNullOrWhiteSpace(registrationModel.Password))
                    {
                        body = $@"שלום,
האבחון של ילד/תך מוכן.
בכדי להוריד את האבחון, כנס/י ל: 
ayaneeman.azurewebsites.net
'התחבר/י עם שם המשתמש והסיסמא שלך ולחצ/י על - 'האבחונים שלי.
לשאלות נוספות, ניתן להשיב לאימייל הזה או להתקשר אלי לטלפון: 0522204509

תודה,
איה.";
                    }
                    else
                    {
                        body = $@"שלום,
האבחון של ילד/תך מוכן.
בכדי להוריד את האבחון, כנס/י ל: 
ayaneeman.azurewebsites.net
שם המשתמש: {ivhun.ParentEmail}
סיסמא: {registrationModel.Password}
לשאלות נוספות, ניתן להשיב לאימייל הזה או להתקשר אלי לטלפון: 0522204509

תודה,
איה.";
                    }


                    if (string.IsNullOrWhiteSpace(ivhun.ParentEmail))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        var          fromAddress  = new MailAddress("*****@*****.**", "איה נאמן");
                        var          toAddress    = new MailAddress(ivhun.ParentEmail, ivhun.FirstName + " " + ivhun.LastName);
                        const string fromPassword = "******";
                        const string subject      = "איה נאמן - אבחון";
                        var          smtp         = new SmtpClient
                        {
                            Host                  = "smtp.gmail.com",
                            Port                  = 587,
                            EnableSsl             = true,
                            DeliveryMethod        = SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = false,
                            Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                        };
                        using (var message = new MailMessage(fromAddress, toAddress)
                        {
                            Subject = subject,
                            Body = body,
                            IsBodyHtml = false
                        })
                        {
                            smtp.Send(message);
                        }
                    }
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }