コード例 #1
0
        // UREDI SAMO ROLU ZAPOSLENIKA
        public bool editOnlyEmpRol(Employee employee)
        {
            string prviURI = "removeaccfromemployee";
            string prviZaj = BASE_URL_ASSIGN + prviURI;

            string drugiURI = "addacctoemployee";
            string drugiZaj = BASE_URL_ASSIGN + drugiURI;

            int    oldRole   = 0;
            int    newRoleID = 0;
            string newRolID  = null;

            using (BazaEmployeeEntities ben = new BazaEmployeeEntities())
            {
                try
                {
                    int           cid = Convert.ToInt32(employee.Id);
                    EmployeeTable et  = ben.EmployeeTables.Single(ete => ete.ZaposlenikID == cid);
                    oldRole   = et.RoleID;
                    et.RoleID = employee.RoleID;
                    ben.SaveChanges();
                    newRoleID = et.RoleID;
                    newRolID  = newRoleID.ToString();
                }
                catch
                {
                    return(false);
                }

                // pozivanje removeAccFromEmployee
                int        employeeId    = employee.Id; // id zaposlenika koji se prosljeđuje
                EmpAccMapp empaccmappDel = new EmpAccMapp(employeeId, oldRole);

                DataContractJsonSerializer serDel = new DataContractJsonSerializer(typeof(EmpAccMapp));
                MemoryStream memDel = new MemoryStream();
                serDel.WriteObject(memDel, empaccmappDel);
                string dataDel = Encoding.UTF8.GetString(memDel.ToArray(), 0, (int)memDel.Length);

                WebClient webClientDel = new WebClient();
                webClientDel.Headers["Content-type"] = "application/json";
                webClientDel.Encoding = Encoding.UTF8;
                webClientDel.UploadString(prviZaj, "DELETE", dataDel);

                // pozivanje addAccountToEmployee
                EmpAccMapp empaccmappAdd = new EmpAccMapp(employee.Id, employee.RoleID);

                DataContractJsonSerializer serAdd = new DataContractJsonSerializer(typeof(EmpAccMapp));
                MemoryStream memAdd = new MemoryStream();
                serAdd.WriteObject(memAdd, empaccmappAdd);
                string dataAdd = Encoding.UTF8.GetString(memAdd.ToArray(), 0, (int)memAdd.Length);

                WebClient webClientAdd = new WebClient();
                webClientAdd.Headers["Content-type"] = "application/json";
                webClientAdd.Encoding = Encoding.UTF8;
                webClientAdd.UploadString(drugiZaj, "POST", dataAdd);
                return(true);
            }
        }
コード例 #2
0
        // KREIRAJ ZAPOSLENIKA
        public bool createEmp(Employee employee)
        {
            string uriAddAccToEmp = "addacctoemployee";
            string zajednoURI     = BASE_URL_ASSIGN + uriAddAccToEmp;
            int    empID          = 0;
            int    roleID         = 0;

            using (BazaEmployeeEntities ben = new BazaEmployeeEntities())
            {
                try
                {
                    EmployeeTable emt = new EmployeeTable();
                    emt.ImeZap     = employee.Ime;
                    emt.PrezimeZap = employee.Prezime;
                    emt.AdresaZap  = employee.Adresa;
                    emt.GradZap    = employee.Grad;
                    emt.RoleID     = employee.RoleID;
                    ben.EmployeeTables.Add(emt);
                    ben.SaveChanges();

                    empID  = emt.ZaposlenikID;
                    roleID = emt.RoleID;
                }
                catch
                {
                    return(false);
                }
            }

            // pozivanje AddAccountToEmployee
            EmpAccMapp empaccmapp = new EmpAccMapp(empID, roleID);

            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(EmpAccMapp));
            MemoryStream mem  = new MemoryStream(); ser.WriteObject(mem, empaccmapp);
            string       data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);

            WebClient webClient = new WebClient();

            webClient.Headers["Content-type"] = "application/json";
            webClient.Encoding = Encoding.UTF8;
            webClient.UploadString(zajednoURI, "POST", data);

            return(true);
        }