Example #1
0
        public Result<WorkerSkill> Save(WorkerSkill Entity)
        {
            var result = new Result<WorkerSkill>();
            try
            {

                _context.workerSkills.FirstOrDefault(u => u.SkillId == Entity.SkillId);
                var objtosave = _context.workerSkills.FirstOrDefault(u => u.SkillId == Entity.SkillId);
                if (objtosave == null)
                {
                    objtosave = new WorkerSkill();
                    _context.workerSkills.Add(objtosave);
                }
                objtosave.SkillId = Entity.SkillId;
                objtosave.UserId = Entity.UserId;




                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                result.HasError = true;
                result.Message = ex.Message;
            }
            return result;
        }
        private Data GetSkillData(string id, WorkerSkill workerSkill)
        {
            Data data = new Data()
            {
                Name = "worker",
                Url  = new System.Uri(Request.Headers.Host + "/api/worker/" + id + "/skill")
            };

            data.Rel = new List <string>();
            data.Rel.Add("item");
            data.Rel.Add(Request.Headers.Host + "/api/rels/worker");

            List <Data> children = new List <Data>();

            children.Add(new Data {
                Name = "workerNumber", Label = "Worker Number", Value = workerSkill == null ? null : workerSkill.workerNumber
            });
            children.Add(new Data {
                Name = "firstName", Label = "First Name", Value = workerSkill == null ? null : workerSkill.firstName
            });
            children.Add(new Data {
                Name = "lastName", Label = "Last Name", Value = workerSkill == null ? null : workerSkill.lastName
            });
            children.Add(new Data {
                Name = "skill", Label = "Skill", Value = workerSkill == null ? null : workerSkill.skill
            });
            children.Add(new Data {
                Name = "experience", Label = "Experience", Value = workerSkill == null ? null : workerSkill.experience
            });

            data.Children = children;

            return(data);
        }
Example #3
0
    public WorkerInfo Get(string WorkerID)
    {
        db.Open();
        WorkerClientList clientListObj    = new WorkerClientList();
        WorkerSkill      WorkerSkill      = new WorkerSkill();
        WorkerAdjustment WorkerAdjustment = new WorkerAdjustment();
        WorkerAttachment WorkerAttachment = new WorkerAttachment();

        string query = "select * from Worker "
                       + " where WorkerID = @WorkerID ";

        try
        {
            var        obj = (List <WorkerInfo>)db.Query <WorkerInfo>(query, new { WorkerID = WorkerID });
            WorkerInfo info;
            if (obj.Count > 0)
            {
                info                = obj[0];
                info.ClientList     = clientListObj.Get(WorkerID);
                info.SkillList      = WorkerSkill.GetSkillList(WorkerID);
                info.AdjustmentList = WorkerAdjustment.GetList(WorkerID);
                info.AttachmentList = WorkerAttachment.GetList(WorkerID);
                return(info);
            }
            else
            {
                return(null);
            }
        }
        finally
        {
            db.Close();
        }
    }
Example #4
0
        public ActionResult DeleteConfirmed(string id, int?skillID)
        {
            id = User.Identity.GetUserId();
            WorkerSkill workerSkill = db.WorkerSkills.Find(id, skillID);

            db.WorkerSkills.Remove(workerSkill);
            db.SaveChanges();
            return(RedirectToRoute("Default", new { controller = "Manage", action = "Index" }));
        }
Example #5
0
        public static WorkerSkill CreateWorkerSkill(string personnelNumber, string skillId, global::System.DateTimeOffset levelDate, decimal yearsOfExperience)
        {
            WorkerSkill workerSkill = new WorkerSkill();

            workerSkill.PersonnelNumber   = personnelNumber;
            workerSkill.SkillId           = skillId;
            workerSkill.LevelDate         = levelDate;
            workerSkill.YearsOfExperience = yearsOfExperience;
            return(workerSkill);
        }
Example #6
0
        // GET: WorkerSkills/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WorkerSkill workerSkill = db.WorkerSkills.Find(id);

            if (workerSkill == null)
            {
                return(HttpNotFound());
            }
            return(View(workerSkill));
        }
Example #7
0
        public ActionResult Edit([Bind(Exclude = "WorkerID", Include = "SkillID,YearsOfExperience")] WorkerSkill workerSkill)
        {
            workerSkill.WorkerID = User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                db.Entry(workerSkill).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToRoute("Default", new { controller = "Manage", action = "Index" }));;
            }
            ViewBag.SkillID = new SelectList(db.Skills, "SkillID", "SkillDescription", workerSkill.SkillID);

            return(View(workerSkill));
        }
Example #8
0
        // GET: WorkerSkills/Edit/5
        public ActionResult Edit(string id, int skill)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WorkerSkill workerSkill = db.WorkerSkills.Find(id, skill);

            if (workerSkill == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SkillID   = skill;
            ViewBag.SkillName = workerSkill.Skill.SkillDescription;

            return(View(workerSkill));
        }
Example #9
0
        // GET: WorkerSkills/Delete/5
        public ActionResult Delete(string id, int?skillID)
        {
            id = User.Identity.GetUserId();
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            WorkerSkill workerSkill = db.WorkerSkills.Find(id, skillID);

            if (workerSkill == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SkillID = new SelectList(db.Skills, "SkillID", "SkillDescription", workerSkill.SkillID);

            return(View(workerSkill));
        }
        public ActionResult Skills(string[] SkillName)
        {
            for (int i = 0; i < SkillName.Length; i++)
            {
                var skillTbl = _skillService.GetAll().Data.FirstOrDefault(d => d.SkillName.Equals(SkillName[i]));
                if (skillTbl != null)
                {
                    var objToSave = new WorkerSkill();
                    objToSave.UserId  = HttpUtil.CurrentUser.UserId;
                    objToSave.SkillId = skillTbl.SkillId;
                    _workerSkillService.Save(objToSave);
                }
            }

            //var objtosave=new WorkerSkill();
            //objtosave.SkillId = model.SkillId;
            //objtosave.UserId=model.
            return(RedirectToAction("Profile", "Worker"));
        }
Example #11
0
        public ActionResult Create([Bind(Exclude = "WorkerID", Include = "SkillID,YearsOfExperience")] WorkerSkill workerSkill, string returnUrl)
        {
            string user = User.Identity.GetUserId();


            workerSkill.WorkerID = user;
            var result = db.WorkerSkills.Find(user, workerSkill.SkillID);

            if (result != null)
            {
                TempData["exist"] = "You already added this skill. Please select a differnt one.";
                ViewBag.SkillID   = new SelectList(db.Skills, "SkillID", "SkillDescription", workerSkill.SkillID);
                ViewBag.WorkerID  = User.Identity.GetUserId();
                return(View(workerSkill));
            }

            if (ModelState.IsValid)
            {
                db.WorkerSkills.Add(workerSkill);
                db.SaveChanges();
                TempData["Skill"] = "Skill Added Successfully";

                return(RedirectToRoute("Default", new { controller = "Manage", action = "Index" }));
            }

            ViewBag.SkillID  = new SelectList(db.Skills, "SkillID", "SkillDescription", workerSkill.SkillID);
            ViewBag.WorkerID = User.Identity.GetUserId();

            if (!string.IsNullOrEmpty(returnUrl))
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(View(workerSkill));
            }
        }
Example #12
0
 public bool IsValid(WorkerSkill obj, Result<WorkerSkill> result)
 {
     throw new NotImplementedException();
 }
Example #13
0
    public string Save(WorkerInfo info)
    {
        this.db.Open();
        this.transaction = this.db.BeginTransaction();
        try
        {
            if (this.IsExisted(info))
            {
                this.Update(info);
            }
            else
            {
                this.Insert(info);
            }

            WorkerClientList clientListObj = new WorkerClientList(this.db, this.transaction);
            clientListObj.Save(info.ClientList, info.WorkerID);

            int         rowno       = 0;
            WorkerSkill WorkerSkill = new WorkerSkill(this.db, this.transaction);
            if (info.SkillList != null)
            {
                foreach (WorkerSkillInfo skill in info.SkillList)
                {
                    skill.WorkerID = info.WorkerID;
                    skill.RowNo    = ++rowno;
                    WorkerSkill.Save(skill);
                }
            }
            WorkerSkill.Delete(info.WorkerID, ++rowno);


            WorkerAdjustment WorkerAdjustment = new WorkerAdjustment(this.db, this.transaction);
            rowno = 0;
            if (info.AdjustmentList != null)
            {
                foreach (WorkerAdjustmentInfo adjust in info.AdjustmentList)
                {
                    adjust.WorkerID = info.WorkerID;
                    adjust.RowNo    = ++rowno;
                    WorkerAdjustment.Save(adjust);
                }
            }
            WorkerAdjustment.Delete(info.WorkerID, ++rowno);



            WorkerAttachment WorkerAttachment = new WorkerAttachment(this.db, this.transaction);
            rowno = 0;
            List <int> existingRowNo = new List <int>();
            if (info.AttachmentList != null)
            {
                foreach (WorkerAttachmentInfo adjust in info.AttachmentList)
                {
                    existingRowNo.Add(adjust.RowNo);

                    adjust.WorkerID = info.WorkerID;
                    WorkerAttachment.Save(adjust);
                }
            }
            WorkerAttachment.Delete(info.WorkerID, existingRowNo);


            this.transaction.Commit();
        }
        catch
        {
            this.transaction.Rollback();
            throw;
        }
        finally
        {
            this.db.Close();
        }

        return(info.WorkerID);
    }
        public IHttpActionResult GetWorkerSkill(string id)
        {
            var query = WebApiConfig.GraphClient.Cypher
                        .Match("(w:Worker)-[e:EXPERTIN]->(s:Skill)")
                        .Where((Worker w) => w.id == id)
                        .Return((w, s) => new
            {
                worker = w.As <Worker>(),
                skill  = Return.As <string>("collect(s.name)")
            });

            var queryData = query.Results.ToList();

            var workerSkills = new List <WorkerSkill>();

            foreach (var item in queryData)
            {
                WorkerSkill workerSkill = new WorkerSkill
                {
                    workerNumber = item.worker.number,
                    firstName    = item.worker.firstName,
                    lastName     = item.worker.lastName,
                    skill        = item.skill,
                    experience   = "EXPERT"
                };
                workerSkills.Add(workerSkill);
            }

            query = WebApiConfig.GraphClient.Cypher
                    .Match("(w:Worker)-[e:PROFICIENTIN]->(s:Skill)")
                    .Where((Worker w) => w.id == id)
                    .Return((w, s) => new
            {
                worker = w.As <Worker>(),
                skill  = Return.As <string>("collect(s.name)")
            });

            queryData = query.Results.ToList();

            foreach (var item in queryData)
            {
                WorkerSkill workerSkill = new WorkerSkill
                {
                    workerNumber = item.worker.number,
                    firstName    = item.worker.firstName,
                    lastName     = item.worker.lastName,
                    skill        = item.skill,
                    experience   = "PROFICIENT"
                };
                workerSkills.Add(workerSkill);
            }


            UberDocument uberDocument = new UberDocument {
                Version = "1.0", Data = new List <Data>()
            };

            if (workerSkills.Count > 0)
            {
                Data data = new Data();
                data.Rel = new List <string>();
                data.Rel.Add("self");
                data.Rel.Add(Request.Headers.Host + "/api/worker/" + id + "/skill");
                List <Data> result = new List <Data>();

                foreach (WorkerSkill ws in workerSkills)
                {
                    result.Add(GetSkillData(id, ws));
                }

                data.Children = result;
                uberDocument.Data.Add(data);
            }

            string uber = JsonConvert.SerializeObject(uberDocument, Formatting.None, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            return(Ok(new { uber }));
        }