Ejemplo n.º 1
0
        public async Task <ActionResult> EditAddEquipment(DailyWorkEquipmentData dailyWorkEquipmentData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                DailyWork dailyWork = db.DailyWorks.FirstOrDefault(m => m.ID == dailyWorkEquipmentData.DailyWork.ID);

                dailyWorkEquipmentData.EquipmentUnit.DailyWorkID = dailyWorkEquipmentData.DailyWork.ID;
                dailyWorkEquipmentData.EquipmentUnit.Date        = (DateTime)dailyWorkEquipmentData.DailyWork.Date;

                EquipmentUnit equipTemp = db.EquipmentUnits.FirstOrDefault(e => e.NameVn.Equals(dailyWorkEquipmentData.EquipmentUnit.NameVn));
                if (equipTemp != null)
                {
                    dailyWorkEquipmentData.EquipmentUnit.NameKr = equipTemp.NameKr;
                    if (dailyWorkEquipmentData.EquipmentUnit.NoteVn == null)
                    {
                        dailyWorkEquipmentData.EquipmentUnit.Translate = equipTemp.Translate;
                    }
                }


                db.EquipmentUnits.Add(dailyWorkEquipmentData.EquipmentUnit);
                dailyWork.EquipmentUnits.Add(dailyWorkEquipmentData.EquipmentUnit);

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddEquipment", new { id = dailyWorkEquipmentData.DailyWork.ID }));
            }
            return(View(dailyWorkEquipmentData));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> EditEditWork(int id, int workid, DailyWorkUnitData dailyWorkUnitData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                DailyWork dailyWork = db.DailyWorks.FirstOrDefault(m => m.ID == dailyWorkUnitData.DailyWork.ID);
                WorkUnit  workUnit  = await db.WorkUnits.FindAsync(workid);

                if (workUnit.WorkNameVn != dailyWorkUnitData.WorkUnit.WorkNameVn)
                {
                    workUnit.Translate = false;
                }
                if (workUnit.NoteVn != dailyWorkUnitData.WorkUnit.NoteVn)
                {
                    workUnit.Translate = false;
                }
                workUnit.StartDate  = dailyWorkUnitData.WorkUnit.StartDate;
                workUnit.EndDate    = dailyWorkUnitData.WorkUnit.EndDate;
                workUnit.Complete   = dailyWorkUnitData.WorkUnit.Complete;
                workUnit.WorkNameVn = dailyWorkUnitData.WorkUnit.WorkNameVn;
                workUnit.NoteVn     = dailyWorkUnitData.WorkUnit.NoteVn;

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddWork", new { id = dailyWorkUnitData.DailyWork.ID }));
            }
            return(View(dailyWorkUnitData));
        }
Ejemplo n.º 3
0
        public void DeleteDailyWork(int DailyWorkId)
        {
            DailyWork DailyWorkRecord = _db.DailyWork.Find(DailyWorkId);

            _db.DailyWork.Remove(DailyWorkRecord);
            _db.SaveChanges();
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> EditEditEquipment(int?id, int equipmentid)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DailyWork dailyWork = await db.DailyWorks.FindAsync(id);

            if (dailyWork == null)
            {
                return(HttpNotFound());
            }
            EquipmentUnit equipmentUnit = await db.EquipmentUnits.FindAsync(equipmentid);

            if (equipmentUnit == null)
            {
                return(HttpNotFound());
            }
            var dailyWorkEquipmentData = new DailyWorkEquipmentData();

            dailyWorkEquipmentData.DailyWork     = dailyWork;
            dailyWorkEquipmentData.EquipmentUnit = equipmentUnit;

            dailyWorkEquipmentData.DailyWork.EquipmentUnits = dailyWorkEquipmentData.DailyWork.EquipmentUnits.OrderBy(p => p.ID).ToList();

            ViewBag.WorkUnits = db.WorkUnits.Where(w => w.ProjectID == dailyWork.ProjectID && w.StartDate <= dailyWork.Date &&
                                                   (w.Complete == false || w.EndDate >= dailyWork.Date)).ToList();

            return(View(dailyWorkEquipmentData));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> EditEditEquipment(int id, int equipmentid, DailyWorkEquipmentData dailyWorkEquipmentData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                DailyWork     dailyWork     = db.DailyWorks.FirstOrDefault(m => m.ID == dailyWorkEquipmentData.DailyWork.ID);
                EquipmentUnit equipmentUnit = await db.EquipmentUnits.FindAsync(equipmentid);

                if (equipmentUnit.NoteVn != dailyWorkEquipmentData.EquipmentUnit.NoteVn)
                {
                    equipmentUnit.Translate = false;
                }
                equipmentUnit.Date        = (DateTime)dailyWorkEquipmentData.DailyWork.Date;
                equipmentUnit.DailyWorkID = dailyWorkEquipmentData.DailyWork.ID;
                equipmentUnit.NameKr      = dailyWorkEquipmentData.EquipmentUnit.NameKr;
                equipmentUnit.NameVn      = dailyWorkEquipmentData.EquipmentUnit.NameVn;
                equipmentUnit.NoteVn      = dailyWorkEquipmentData.EquipmentUnit.NoteVn;
                equipmentUnit.NoteKr      = dailyWorkEquipmentData.EquipmentUnit.NoteKr;
                equipmentUnit.EquipCount  = dailyWorkEquipmentData.EquipmentUnit.EquipCount;

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddEquipment", new { id = dailyWorkEquipmentData.DailyWork.ID }));
            }
            return(View(dailyWorkEquipmentData));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            DailyWork dailyWork = await db.DailyWorks.FindAsync(id);

            int projectID = dailyWork.ProjectID;

            db.DailyWorks.Remove(dailyWork);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index", new { projectid = projectID }));
        }
Ejemplo n.º 7
0
        // GET: DailyWork/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DailyWork dailyWork = await db.DailyWorks.FindAsync(id);

            if (dailyWork == null)
            {
                return(HttpNotFound());
            }
            return(View(dailyWork));
        }
Ejemplo n.º 8
0
        // GET: DailyWork/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DailyWork dailyWork = await db.DailyWorks.FindAsync(id);

            if (dailyWork == null)
            {
                return(HttpNotFound());
            }
            ViewBag.WorkUnits = db.WorkUnits.Where(w => w.ProjectID == dailyWork.ProjectID && w.StartDate <= dailyWork.Date &&
                                                   (w.Complete == false || w.EndDate >= dailyWork.Date)).ToList();
            ViewBag.AllEquips = db.EquipmentUnits.Where(e => e.ID > 0).ToList();
            return(View(dailyWork));
        }
        public async Task <ActionResult> EditEditWorkUnit(int id, int workunitid, FactoryDailyWorkUnitData factoryDailyWorkUnitData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                DailyWork       dailyWork = db.DailyWorks.FirstOrDefault(m => m.ID == factoryDailyWorkUnitData.DailyWork.ID);
                FactoryWorkUnit workUnit  = await db.FactoryWorkUnits.FindAsync(workunitid);

//                workUnit.Date = (DateTime)factoryDailyWorkUnitData.DailyWork.Date;
                workUnit.FactoryDailyWorkID = factoryDailyWorkUnitData.DailyWork.ID;
                workUnit.ProjectID          = factoryDailyWorkUnitData.WorkUnit.ProjectID;
//                equipmentUnit.NameKr = factoryDailyWorkUnitData.WorkUnit.NameKr;
//                equipmentUnit.NameVn = factoryDailyWorkUnitData.WorkUnit.NameVn;

                if (Convert.ToInt32(Session["CurrentCulture"]) == 2)
                {
                    if (!workUnit.NoteKr.Equals(factoryDailyWorkUnitData.WorkUnit.NoteVn))
                    {
                        workUnit.NoteVn    = factoryDailyWorkUnitData.WorkUnit.NoteVn;
                        workUnit.NoteKr    = factoryDailyWorkUnitData.WorkUnit.NoteVn;
                        workUnit.Translate = false;
                    }
                }
                else
                {
                    if (!workUnit.NoteVn.Equals(factoryDailyWorkUnitData.WorkUnit.NoteVn))
                    {
                        workUnit.NoteVn    = factoryDailyWorkUnitData.WorkUnit.NoteVn;
                        workUnit.NoteKr    = factoryDailyWorkUnitData.WorkUnit.NoteVn;
                        workUnit.Translate = false;
                    }
                }
                workUnit.EquipCount = factoryDailyWorkUnitData.WorkUnit.EquipCount;

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddWorkUnit", new { id = factoryDailyWorkUnitData.DailyWork.ID }));
            }
            return(View(factoryDailyWorkUnitData));
        }
Ejemplo n.º 10
0
        // GET: DailyWork/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DailyWork dailyWork = await db.DailyWorks.FindAsync(id);

            if (dailyWork == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProjectID         = new SelectList(db.Projects, "ID", "NameVn", dailyWork.ProjectID);
            ViewBag.ProparingPersonID = new SelectList(db.Employees.Where(e => e.ResignID == null), "ID", "Name", dailyWork.ProparingPersonID);
            ViewBag.WorkUnits         = db.WorkUnits.Where(w => w.ProjectID == dailyWork.ProjectID && w.StartDate <= dailyWork.Date &&
                                                           (w.Complete == false || w.EndDate >= dailyWork.Date)).ToList();
            return(View(dailyWork));
        }
Ejemplo n.º 11
0
        // GET: DailyWork/Create
        public ActionResult Create(int?projectid)
        {
            DailyWork dailyWork = new DailyWork();

            if (projectid == null)
            {
                ViewBag.ProjectID = new SelectList(db.Projects, "ID", "NameVn");
            }
            else
            {
                Project project = db.Projects.FirstOrDefault(p => p.ID == projectid);
                ViewBag.ProjectID     = projectid;
                ViewBag.ProjectNameVn = project.NameVn;
                ViewBag.ProjectNameKr = project.NameKr;
                dailyWork.ProjectID   = (int)projectid;
            }

            ViewBag.ProparingPersonID = new SelectList(db.Employees.Where(e => e.ResignID == null), "ID", "Name");
            return(View(dailyWork));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,ProjectID,ProparingPersonID,Date,PrrocessPerPlan,PrrocessPerResult,WeatherVn,WeatherKr,NoteVn,NoteKr,UploadFiles,Translate")] DailyWork dailyWork)
        {
            if (ModelState.IsValid)
            {
                db.Entry(dailyWork).State = EntityState.Modified;

                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file != null && file.ContentLength > 0)
                    {
                        var        fileName   = Path.GetFileName(file.FileName);
                        UploadFile uploadFile = new UploadFile()
                        {
                            FileName     = fileName,
                            SaveFileName = Guid.NewGuid() + "_" + fileName,
                            FolderName   = "DailyWork",
                            Date         = DateTime.Now
                        };
                        var path = Path.Combine(Server.MapPath("~/UploadFile/"), uploadFile.FolderName + "/" + uploadFile.SaveFileName);
                        file.SaveAs(path);

                        db.Entry(uploadFile).State = EntityState.Added;

                        if (dailyWork.UploadFiles == null)
                        {
                            dailyWork.UploadFiles = new List <UploadFile>();
                        }
                        dailyWork.UploadFiles.Add(uploadFile);
                    }
                }

                await db.SaveChangesAsync();

                return(RedirectToAction("Index", new { projectid = dailyWork.ProjectID, translate = Session["Translate"] }));
            }
            ViewBag.ProjectID         = new SelectList(db.Projects, "ID", "NameVn", dailyWork.ProjectID);
            ViewBag.ProparingPersonID = new SelectList(db.Employees.Where(e => e.ResignID == null), "ID", "Name", dailyWork.ProparingPersonID);
            return(View(dailyWork));
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> Create([Bind(Include = "ID,ProjectID,ProparingPersonID,Date,PrrocessPerPlan,PrrocessPerResult,WeatherVn,WeatherKr,NoteVn,NoteKr,Translate,WorkUnits")] DailyWork dailyWork)
        {
            if (ModelState.IsValid)
            {
                //                dailyWork.Project.WorkUnits = db.WorkUnits.Where(w => w.DailyWorks.Count(d=>d.ProjectID == dailyWork.ProjectID)>0 && w.StartDate < dailyWork.Date && w.Complete == false).ToList();
                List <UploadFile> UploadFiles = new List <UploadFile>();
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file != null && file.ContentLength > 0)
                    {
                        var        fileName   = Path.GetFileName(file.FileName);
                        UploadFile uploadFile = new UploadFile()
                        {
                            FileName     = fileName,
                            SaveFileName = Guid.NewGuid() + "_" + fileName,
                            FolderName   = "DailyWork",
                            Date         = DateTime.Now
                        };
                        UploadFiles.Add(uploadFile);

                        var path = Path.Combine(Server.MapPath("~/UploadFile/"), uploadFile.FolderName + "/" + uploadFile.SaveFileName);
                        file.SaveAs(path);
                    }
                }

                dailyWork.UploadFiles = UploadFiles;

                db.DailyWorks.Add(dailyWork);
                await db.SaveChangesAsync();

//                return RedirectToAction("Index");
                return(RedirectToAction("EditAddWork", new { id = dailyWork.ID }));
            }

            ViewBag.ProjectID         = new SelectList(db.Projects, "ID", "NameVn", dailyWork.ProjectID);
            ViewBag.ProparingPersonID = new SelectList(db.Employees.Where(e => e.ResignID == null), "ID", "Name", dailyWork.ProparingPersonID);
            return(View(dailyWork));
        }
Ejemplo n.º 14
0
        // GET: DailyWorks
        public async Task <IActionResult> Index()
        {
            string sql = "Select R.UserName, T.Name as Track, CAST(R.TaskStart AS DATE) as startDate, sum(DATEDIFF(minute, R.TaskStart, TaskEnd)) as minutes " +
                         "from Record[R] Join Track[T] ON R.TrackId = T.TrackId " +
                         "WHERE YEAR(R.TaskEnd) >= 2000 " +
                         "GROUP BY R.UserName, T.Name, CAST(R.TaskStart AS DATE)";
            List <DailyWork> works = new List <DailyWork>();
            var conn = _context.Database.GetDbConnection();

            try
            {
                await conn.OpenAsync();

                using (var command = conn.CreateCommand())
                {
                    command.CommandText = sql;
                    DbDataReader reader = await command.ExecuteReaderAsync();

                    if (reader.HasRows)
                    {
                        while (await reader.ReadAsync())
                        {
                            var row = new DailyWork {
                                UserName = reader.GetString(0), Track = reader.GetString(1), StartDate = reader.GetDateTime(2), Minutes = reader.GetInt32(3)
                            };
                            works.Add(row);
                        }
                    }
                    reader.Dispose();
                }
            }
            finally
            {
                conn.Close();
            }

            return(View(works.ToList()));
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> EditAddWork(DailyWorkUnitData dailyWorkUnitData)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid)
            {
                //                db.Entry(materialBuyData).State = EntityState.Modified;
                DailyWork dailyWork = db.DailyWorks.FirstOrDefault(m => m.ID == dailyWorkUnitData.DailyWork.ID);

                dailyWorkUnitData.WorkUnit.WorkNameKr = dailyWorkUnitData.WorkUnit.WorkNameVn;
                dailyWorkUnitData.WorkUnit.NoteKr     = dailyWorkUnitData.WorkUnit.NoteVn;

                db.WorkUnits.Add(dailyWorkUnitData.WorkUnit);
                dailyWork.Project.WorkUnits.Add(dailyWorkUnitData.WorkUnit);

                await db.SaveChangesAsync();

                return(RedirectToAction("EditAddWork", new { id = dailyWorkUnitData.DailyWork.ID }));
            }
            return(View(dailyWorkUnitData));
        }
Ejemplo n.º 16
0
 public DailyWork AddDailyWork(DailyWork DailyWorkRecord)
 {
     _db.DailyWork.Add(DailyWorkRecord);
     _db.SaveChanges();
     return(DailyWorkRecord);
 }
Ejemplo n.º 17
0
 public DailyWork UpdateDailyWork(DailyWork DailyWorkRecord)
 {
     _db.Entry(DailyWorkRecord).State = EntityState.Modified;
     _db.SaveChanges();
     return(DailyWorkRecord);
 }
Ejemplo n.º 18
0
        public static bool IsAccomplishedDailyGoal(this Monster monster, DailyWork dailyWork)
        {
            int monsterDailyQuota = ((dailyWork.Date.Year - monster.StartedScaring.Year)) * 20 + 100;

            return(dailyWork.DepletedDoors.Sum(d => d.Power) >= monsterDailyQuota);
        }
Ejemplo n.º 19
0
        public async Task <BlTResult <DailyWorkResponse> > GetWorkAsync(DailyWorkRequest request, Monster monster)
        {
            try
            {
                IEnumerable <Monsters.DAL.Models.Scare> response = await _repository.GetScaresByDateAsync(request.From, request.To, monster.Id).ConfigureAwait(false);

                if (response.Count() == 0)
                {
                    string msg = $"No work found;";
                    return(new BlTResult <DailyWorkResponse>()
                    {
                        IsSuccess = false, ErrorMsg = msg
                    });
                }

                var dailyWorkResponse = new DailyWorkResponse()
                {
                    DailyWork = new List <DailyWork>()
                };


                DailyWork dailyWork = new DailyWork()
                {
                    Date          = response.First().ScareBegin.Date,
                    DepletedDoors = new List <View.Models.Door>()
                };

                foreach (Monsters.DAL.Models.Scare scare in response)
                {
                    //if we moved to the next day
                    //Wrap the prev day and add it to result
                    if (scare.ScareBegin.Date != dailyWork.Date)
                    {
                        dailyWork.FilledQuota = monster.IsAccomplishedDailyGoal(dailyWork);
                        //Add the day to response if we dont filter by accomplish
                        //or if we do filter by accomplish and the monster accomplished his daily quota that day
                        if (!request.FilterByAccomplishedGoal || dailyWork.FilledQuota)
                        {
                            dailyWorkResponse.DailyWork.Add(dailyWork);
                        }

                        //Start new day
                        dailyWork = new DailyWork()
                        {
                            Date          = scare.ScareBegin.Date,
                            DepletedDoors = new List <View.Models.Door>()
                        };
                    }
                    //add the scare to the day
                    dailyWork.DepletedDoors.Add(PrimitiveMapperHelper.Map(scare.Door));
                }

                return(new BlTResult <DailyWorkResponse>()
                {
                    IsSuccess = true, Data = dailyWorkResponse
                });
            }
            catch (Exception ex)
            {
                string errorMsg = $"Exception thrown trying to get daily work. Error {ex.ToString()}.";
                _logger.LogError(errorMsg);
                return(new BlTResult <DailyWorkResponse>()
                {
                    IsSuccess = false, ErrorMsg = errorMsg
                });
            }
        }