Ejemplo n.º 1
0
        public async Task <IActionResult> P1PAdd(P1PAddVM p)
        {
            if (p.idoper != null)
            {
                if (ModelState.IsValid)
                {
                    IQueryable <Operation> ops = db.Operations.Include(c => c.Plan).Include(p => p.p);
                    ops = ops.Where(u => u.Id == p.idoper);
                    Operation o = new Operation();
                    foreach (Operation op in ops)
                    {
                        o = op;
                        break;
                    }
                    db.Ps.Add(new P {
                        Name = p.Name, Data = DateTime.Now, Coment = p.Coment, Sum = p._Sum, Operation = o
                    });
                    await db.SaveChangesAsync();

                    int pr1 = o.Sum / 100;
                    o.SumP   += p._Sum;// общая сумма всех соверш опер
                    o.Procent = o.SumP / pr1;
                    // считаем процент выполнения плана складываем проценты всех операций и делим на кол во опер
                    int count = 0;
                    int pr    = 0;
                    foreach (Operation op1 in o.Plan.Operations)
                    {
                        pr += op1.Procent;
                        count++;
                    }
                    o.Plan.Procent      = pr / count;
                    o.Plan.SumRealOper += o.SumP;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("P1PHome", "Home", new { idoper = p.idoper }));
                }
                return(View(p));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    IQueryable <User> users = db.Users.Include(c => c.P1s);
                    users = users.Where(u => u.Email == User.Identity.Name);
                    User us = new User();
                    foreach (User u in users)
                    {
                        us = u;
                        break;
                    }
                    db.P1s.Add(new P1 {
                        Name = p.Name, Data = DateTime.Now, Coment = p.Coment, Sum = p._Sum, NameAct = p.NameAct, User = us
                    });
                    await db.SaveChangesAsync();

                    return(RedirectToAction("P1PHome", "Home"));
                }
                return(View(p));
            }
        }
Ejemplo n.º 2
0
 public IActionResult P1PAdd(int?idoper)
 {
     if (idoper != null)
     {
         P1PAddVM p = new P1PAddVM();
         p.idoper = idoper;
         return(View(p));
     }
     else
     {
         P1PAddVM p = new P1PAddVM();
         return(View(p));
     }
 }